home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / plnk081.zip / pilot-link.0.8.1 / Java / Interface.c < prev    next >
C/C++ Source or Header  |  1997-08-09  |  69KB  |  2,343 lines

  1. #include "Pdapilot_calls.h"
  2. #include "Pdapilot_Database.h"
  3. #include "Pdapilot_Record.h"
  4. #include "Pdapilot_Pref.h"
  5. #include "Pdapilot_Dlp.h"
  6. #include "Pdapilot_AppBlock.h"
  7. #include "Pdapilot_SortBlock.h"
  8. #include "Pdapilot_Resource.h"
  9. #include "Pdapilot_CardInfo.h"
  10. #include "Pdapilot_UserInfo.h"
  11. #include "Pdapilot_SysInfo.h"
  12. #include "Pdapilot_NetInfo.h"
  13. #include "Pdapilot_CategoryAppBlock.h"
  14. #include "Pdapilot_memo_Record.h"
  15. #include "Pdapilot_memo_AppBlock.h"
  16. #include "Pdapilot_todo_Record.h"
  17. #include "Pdapilot_todo_AppBlock.h"
  18. #include "Pdapilot_address_Record.h"
  19. #include "Pdapilot_address_AppBlock.h"
  20. #include "Pdapilot_appointment_Record.h"
  21. #include "Pdapilot_appointment_AppBlock.h"
  22. #include "Pdapilot_appointment_repeat.h"
  23. #include "Pdapilot_appointment_time.h"
  24. #include "Pdapilot_mail_Record.h"
  25. #include "Pdapilot_mail_AppBlock.h"
  26. #include "Pdapilot_mail_SyncPref.h"
  27. #include "Pdapilot_mail_SignaturePref.h"
  28. #include "Pdapilot_mail_sort.h"
  29. #include "Pdapilot_mail_sync.h"
  30. #include "Pdapilot_expense_Record.h"
  31. #include "Pdapilot_expense_AppBlock.h"
  32. #include "Pdapilot_expense_Pref.h"
  33. #include "Pdapilot_expense_type.h"
  34. #include "Pdapilot_expense_payment.h"
  35. #include "Pdapilot_expense_distance.h"
  36. #include "Pdapilot_expense_sort.h"
  37. #include "Pdapilot_expense_CustomCurrency.h"
  38. #include "Pdapilot_RecordID.h"
  39. #include "Pdapilot_Char4.h"
  40. #include "Pdapilot_DBInfo.h"
  41. #include "Pdapilot_File.h"
  42. #include "java_util_Date.h"
  43.  
  44. #include "pi-source.h"
  45.  
  46. #include "pi-dlp.h"
  47. #include "pi-socket.h"
  48. #include "pi-memo.h"
  49. #include "pi-address.h"
  50. #include "pi-datebook.h"
  51. #include "pi-todo.h"
  52. #include "pi-mail.h"
  53. #include "pi-expense.h"
  54. #include "pi-file.h"
  55.  
  56. #include <signal.h>
  57.  
  58. #if (JAVAMAJOR>1) || (JAVAMINOR>0)
  59. # define NEW
  60. #else
  61. # define OLD
  62. #endif
  63.  
  64. #ifdef OLD
  65. # define javaint_t long
  66. #else
  67. # define javaint_t int32_t
  68. #endif
  69.  
  70.  
  71. /** Sun should be ashamed for the 1.0 JNI!
  72.  */
  73.  
  74. static void throwDlpException(int code)
  75. {
  76.     execute_java_static_method(0, FindClass(0, "Pdapilot/DlpException",1),
  77.         "kickWillyScuggins", "(I)V", (long)code);
  78. }
  79.  
  80. static void throwCancelSyncException()
  81. {
  82.     execute_java_static_method(0, FindClass(0, "Pdapilot/CancelSyncException",1),
  83.         "kickWillyScuggins", "()V");
  84. }
  85.  
  86. static void throwIOException(int code)
  87. {
  88.     SignalError(0, "java/lang/IOException", 0);
  89. }
  90.  
  91. static HArrayOfByte * getByteArray(long length)
  92. {
  93.     return (HArrayOfByte*)execute_java_static_method(0, FindClass(0, "Pdapilot/calls",1),
  94.         "getByteArray", "(I)[B", (long)length);
  95. }
  96.  
  97. static HArrayOfObject * makeRecordIDArray(long length)
  98. {
  99.     return (HArrayOfObject*)execute_java_static_method(0, FindClass(0, "Pdapilot/calls",1),
  100.         "makeRecordIDArray", "(I)[LPdapilot/RecordID;", (long)length);
  101. }
  102.  
  103. static HArrayOfObject * makeStringArray(long length)
  104. {
  105.     return (HArrayOfObject*)execute_java_static_method(0, FindClass(0, "Pdapilot/calls",1),
  106.         "makeStringArray", "(I)[Ljava/lang/Object;", (long)length);
  107. }
  108.  
  109. static HArrayOfObject * makeDateArray(long length)
  110. {
  111.     return (HArrayOfObject*)execute_java_static_method(0, FindClass(0, "Pdapilot/calls",1),
  112.         "makeDateArray", "(I)[Ljava/lang/Object;", (long)length);
  113. }
  114.  
  115. static HArrayOfInt * makeIntArray(long length)
  116. {
  117.     return (HArrayOfInt*)execute_java_static_method(0, FindClass(0, "Pdapilot/calls",1),
  118.         "makeIntArray", "(I)[I", (long)length);
  119. }
  120.  
  121. /*static HObject* makeBooleanArray(long length) Ptui!
  122. {
  123.     return (HObject*)execute_java_static_method(0, FindClass(0, "Pdapilot/calls",1),
  124.         "makeBooleanArray", "(I)[Z", (long)length);
  125. }*/
  126.  
  127. static long getArrayLength(struct HArrayOfByte *b)
  128. {
  129.     return (long)execute_java_static_method(0, FindClass(0, "Pdapilot/calls",1),
  130.         "getArrayLength", "([B)I", b);
  131. }
  132.  
  133. static long getObjectArrayLength(struct HArrayOfObject *b)
  134. {
  135.     return (long)execute_java_static_method(0, FindClass(0, "Pdapilot/calls",1),
  136.         "getObjectArrayLength", "([Ljava/lang/Object;)I", b);
  137. }
  138.  
  139. static Hjava_util_Date * makeJavaDate(time_t v) {
  140.     if (v < 18000) {
  141.         return 0;
  142.     } else {
  143.         struct tm * tm = localtime(&v);
  144.         return (Hjava_util_Date*)execute_java_constructor(0, "java/util/Date", 0, 
  145.             "(IIIIII)",
  146.             tm->tm_year, tm->tm_mon, tm->tm_mday,
  147.             tm->tm_hour, tm->tm_min, tm->tm_sec);
  148.     }
  149.     
  150. }    
  151.  
  152. static Hjava_util_Date * makeJavaDateTm(struct tm * tm) {
  153.     return (Hjava_util_Date*)execute_java_constructor(0, "java/util/Date", 0, 
  154.         "(IIIIII)",
  155.         tm->tm_year, tm->tm_mon, tm->tm_mday,
  156.         tm->tm_hour, tm->tm_min, tm->tm_sec);
  157. }    
  158.  
  159. static HPdapilot_Char4 * makeJavaChar4(long id) {
  160.     return (HPdapilot_Char4*)execute_java_constructor(
  161.         0, "Pdapilot/Char4", 0, 
  162.         "(I)", id);
  163. }
  164.  
  165. static unsigned long getJavaChar4(HPdapilot_Char4 * id) {
  166.     if (id)
  167.         return unhand(id)->value;
  168.     else
  169.         return 0;
  170. }
  171.  
  172. static HPdapilot_RecordID * makeJavaRecordID(long id) {
  173.     return (HPdapilot_RecordID*)execute_java_constructor(
  174.         0, "Pdapilot/RecordID", 0, 
  175.         "(I)", id);
  176. }
  177.  
  178. static int getJavaRecordID(HPdapilot_RecordID * id) {
  179.     if (id)
  180.         return unhand(id)->value;
  181.     else
  182.         return 0;
  183. }
  184.  
  185. static time_t readJavaDate(Hjava_util_Date * date) {
  186.     struct tm tm;
  187.  
  188.     tm.tm_year = (int)execute_java_dynamic_method(0, (HObject*)date, "getYear", "()I");
  189.     tm.tm_mon = (int)execute_java_dynamic_method(0, (HObject*)date, "getMonth", "()I");
  190.     tm.tm_mday = (int)execute_java_dynamic_method(0, (HObject*)date, "getDay", "()I");
  191.     tm.tm_hour = (int)execute_java_dynamic_method(0, (HObject*)date, "getHours", "()I");
  192.     tm.tm_min = (int)execute_java_dynamic_method(0, (HObject*)date, "getMinutes", "()I");
  193.     tm.tm_sec = (int)execute_java_dynamic_method(0, (HObject*)date, "getSeconds", "()I");
  194.     
  195.     return mktime(&tm);
  196. }
  197.  
  198. static struct tm * readJavaDateTm(Hjava_util_Date * date) {
  199.     static struct tm tm;
  200.     
  201.     tm.tm_year = (int)execute_java_dynamic_method(0, (HObject*)date, "getYear", "()I");
  202.     tm.tm_mon = (int)execute_java_dynamic_method(0, (HObject*)date, "getMonth", "()I");
  203.     tm.tm_mday = (int)execute_java_dynamic_method(0, (HObject*)date, "getDay", "()I");
  204.     tm.tm_hour = (int)execute_java_dynamic_method(0, (HObject*)date, "getHours", "()I");
  205.     tm.tm_min = (int)execute_java_dynamic_method(0, (HObject*)date, "getMinutes", "()I");
  206.     tm.tm_sec = (int)execute_java_dynamic_method(0, (HObject*)date, "getSeconds", "()I");
  207.     
  208.     return &tm;
  209. }
  210.  
  211. extern javaint_t Pdapilot_calls_pi_socket(struct HPdapilot_calls*self, javaint_t domain, javaint_t type, javaint_t protocol)
  212. {
  213.     int result = pi_socket(domain, type, protocol);
  214.     if (result<0)
  215.         throwIOException(result);
  216.     return result;
  217. }
  218.  
  219. extern javaint_t Pdapilot_calls_pi_bind(struct HPdapilot_calls*self, javaint_t socket, struct Hjava_lang_String * address)
  220. {
  221.     javaint_t len = javaStringLength(address)+3;
  222.     struct pi_sockaddr * a = malloc(len);
  223.     javaint_t result;
  224.     a->pi_family = PI_AF_SLP;
  225.     javaString2CString(address, a->pi_device, len-2);
  226.     result = pi_bind(socket, (struct sockaddr*)a, len);
  227.     free(a);
  228.     if (result<0)
  229.         throwIOException(result);
  230.     return result;
  231. }
  232.  
  233. extern javaint_t Pdapilot_calls_pi_listen(struct HPdapilot_calls*self, javaint_t socket, javaint_t backlog)
  234. {
  235.     int result = pi_listen(socket, backlog);
  236.     if (result<0)
  237.         throwIOException(result);
  238.     return result;
  239.     
  240. }
  241.  
  242. extern javaint_t Pdapilot_calls_pi_accept(struct HPdapilot_calls*self, javaint_t socket)
  243. {
  244.     int result=pi_accept(socket, 0, 0);
  245.     if (result<0)
  246.         throwIOException(result);
  247.     return result;
  248. }
  249.  
  250. extern javaint_t Pdapilot_calls_pi_read(struct HPdapilot_calls*self, javaint_t socket, HArrayOfByte *b, javaint_t len)
  251. {
  252.     int result=pi_read(socket, unhand(b)->body, len);
  253.     if (result<0)
  254.         throwIOException(result);
  255.     return result;
  256. }
  257.  
  258. extern javaint_t Pdapilot_calls_pi_write(struct HPdapilot_calls*self, javaint_t socket, HArrayOfByte * b, javaint_t len)
  259. {
  260.     int result=pi_write(socket, unhand(b)->body, len);
  261.     if (result<0)
  262.         throwIOException(result);
  263.     return result;
  264. }
  265.  
  266. extern javaint_t Pdapilot_calls_pi_close(struct HPdapilot_calls * self, javaint_t socket)
  267. {
  268.     int result=pi_close(socket);
  269.     if (result<0)
  270.         throwIOException(result);
  271.     return result;
  272. }
  273.  
  274. extern javaint_t Pdapilot_calls_pi_version(struct HPdapilot_calls * self, javaint_t socket)
  275. {
  276.     int result=pi_version(socket);
  277.     if (result<0)
  278.         throwIOException(result);
  279.     return result;
  280. }
  281.  
  282. extern javaint_t Pdapilot_calls_pi_watchdog(struct HPdapilot_calls * self, javaint_t socket, javaint_t interval)
  283. {
  284.     int result=pi_watchdog(socket, interval);
  285.     if (result<0)
  286.         throwIOException(result);
  287.     return result;
  288. }
  289.  
  290. extern javaint_t Pdapilot_calls_pi_tickle(struct HPdapilot_calls * self, javaint_t socket)
  291. {
  292.     int result=pi_tickle(socket);
  293.     if (result<0)
  294.         throwIOException(result);
  295.     return result;
  296. }
  297.  
  298. extern javaint_t Pdapilot_calls_dlp_OpenDB(struct HPdapilot_calls * self, javaint_t socket, javaint_t card, javaint_t mode, Hjava_lang_String * name)
  299. {
  300.     int handle;
  301.     int result = dlp_OpenDB(socket, card, mode, makeCString(name), &handle);
  302.     if (result < 0) {
  303.         throwDlpException(result);
  304.         return result;
  305.     }
  306.     return handle;
  307. }
  308.  
  309. extern javaint_t Pdapilot_calls_dlp_CreateDB(struct HPdapilot_calls * self, javaint_t socket, HPdapilot_Char4 * creator, HPdapilot_Char4 * type, javaint_t card, javaint_t flags, javaint_t version, Hjava_lang_String * name)
  310. {
  311.     int handle;
  312.     int result = dlp_CreateDB(socket, unhand(creator)->value, unhand(creator)->value, card, flags, version, makeCString(name), &handle);
  313.     if (result < 0) {
  314.         throwDlpException(result);
  315.         return result;
  316.     }
  317.     return handle;
  318. }
  319.  
  320. extern javaint_t Pdapilot_calls_dlp_DeleteDB(struct HPdapilot_calls * self, javaint_t socket, javaint_t card, Hjava_lang_String * name)
  321. {
  322.     int result = dlp_DeleteDB(socket, card, makeCString(name));
  323.     if (result < 0) {
  324.         throwDlpException(result);
  325.     }
  326.     return result;
  327. }
  328.  
  329. extern Hjava_util_Date * Pdapilot_calls_dlp_GetSysDateTime(struct HPdapilot_calls * self, javaint_t socket)
  330. {
  331.     time_t t;
  332.     int result = dlp_GetSysDateTime(socket, &t);
  333.     if (result < 0) {
  334.         throwDlpException(result);
  335.         return 0;
  336.     }
  337.     
  338.     return makeJavaDate(t);
  339. }
  340.  
  341.  
  342. extern javaint_t Pdapilot_calls_dlp_SetSysDateTime(struct HPdapilot_calls * self, javaint_t socket, Hjava_util_Date * date)
  343. {
  344.     time_t t;
  345.     int result;
  346.     
  347.     t = readJavaDate(date);
  348.     
  349.     result = dlp_SetSysDateTime(socket, t);
  350.     if (result < 0) {
  351.         throwDlpException(result);
  352.     }
  353.     return result;
  354. }
  355.  
  356. extern javaint_t Pdapilot_calls_dlp_AddSyncLogEntry(struct HPdapilot_calls * self, javaint_t socket, Hjava_lang_String * entry)
  357. {
  358.     int result = dlp_AddSyncLogEntry(socket, makeCString(entry));
  359.     if (result < 0)
  360.         throwDlpException(result);
  361.     return result;
  362. }
  363.  
  364. extern javaint_t Pdapilot_calls_dlp_ResetSystem(struct HPdapilot_calls * self, javaint_t socket)
  365. {
  366.     int result = dlp_ResetSystem(socket);
  367.     if (result < 0)
  368.         throwDlpException(result);
  369.     return result;
  370. }
  371.  
  372. extern javaint_t Pdapilot_calls_dlp_EndOfSync(struct HPdapilot_calls * self, javaint_t socket, javaint_t status)
  373. {
  374.     int result = dlp_EndOfSync(socket, status);
  375.     if (result < 0)
  376.         throwDlpException(result);
  377.     return result;
  378. }
  379.  
  380. extern javaint_t Pdapilot_calls_dlp_MoveCategory(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t from, javaint_t to)
  381. {
  382.     int result = dlp_MoveCategory(socket, handle, from, to);
  383.     if (result < 0)
  384.         throwDlpException(result);
  385.     return result;
  386. }
  387.  
  388. extern javaint_t Pdapilot_calls_dlp_DeleteRecord(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t all, HPdapilot_RecordID * id)
  389. {
  390.     int result = dlp_DeleteRecord(socket, handle, all, getJavaRecordID(id));
  391.     if (result < 0)
  392.         throwDlpException(result);
  393.     return result;
  394. }
  395.  
  396. extern javaint_t Pdapilot_calls_dlp_DeleteCategory(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t category)
  397. {
  398.     int result = dlp_DeleteCategory(socket, handle, category);
  399.     if (result < 0)
  400.         throwDlpException(result);
  401.     return result;
  402. }
  403.  
  404. extern javaint_t Pdapilot_calls_dlp_ReadOpenDBInfo(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle)
  405. {
  406.     int count;
  407.     int result = dlp_ReadOpenDBInfo(socket, handle, &count);
  408.     if (result < 0)
  409.         throwDlpException(result);
  410.     return count;
  411. }
  412.  
  413. extern javaint_t Pdapilot_calls_dlp_DeleteResource(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t all, HPdapilot_Char4 * type, javaint_t id)
  414. {
  415.     int result = dlp_DeleteResource(socket, handle, all, unhand(type)->value, id);
  416.     if (result < 0)
  417.         throwDlpException(result);
  418.     return result;
  419. }
  420.  
  421. extern javaint_t Pdapilot_calls_dlp_ResetSyncFlags(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle)
  422. {
  423.     int result = dlp_ResetSyncFlags(socket, handle);
  424.     if (result < 0)
  425.         throwDlpException(result);
  426.     return result;
  427. }
  428.  
  429. extern javaint_t Pdapilot_calls_dlp_CleanUpDatabase(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle)
  430. {
  431.     int result = dlp_CleanUpDatabase(socket, handle);
  432.     if (result < 0)
  433.         throwDlpException(result);
  434.     return result;
  435. }
  436.  
  437.  
  438. extern HPdapilot_CardInfo * Pdapilot_calls_dlp_ReadStorageInfo(struct HPdapilot_calls * self, javaint_t socket, javaint_t card)
  439. {
  440.     HPdapilot_CardInfo * output = NULL;
  441.     struct CardInfo c;
  442.     int result = dlp_ReadStorageInfo(socket, card, &c);
  443.     if (result == -5) {
  444.         return 0;
  445.     } else if (result < 0) {
  446.         throwDlpException(result);
  447.         return 0;
  448.     }
  449.     output = (HPdapilot_CardInfo*)execute_java_constructor(0,
  450.          "Pdapilot/CardInfo", 0, "()");
  451.     unhand(output)->name = makeJavaString(c.name, strlen(c.name));
  452.     unhand(output)->manufacturer = makeJavaString(c.manufacturer, strlen(c.manufacturer));
  453.     unhand(output)->card = c.card;
  454.     unhand(output)->romSize = c.romSize;
  455.     unhand(output)->ramSize = c.ramSize;
  456.     unhand(output)->ramFree = c.ramFree;
  457.     
  458.     unhand(output)->more = c.more;
  459.     unhand(output)->creation = makeJavaDate(c.creation);
  460.  
  461.     return output;
  462. }
  463.  
  464. extern HPdapilot_SysInfo * Pdapilot_calls_dlp_ReadSysInfo(struct HPdapilot_calls * self, javaint_t socket)
  465. {
  466.     HPdapilot_SysInfo * output = NULL;
  467.     struct SysInfo s;
  468.     int result = dlp_ReadSysInfo(socket, &s);
  469.     if (result < 0) {
  470.         throwDlpException(result);
  471.         return 0;
  472.     }
  473.     output = (HPdapilot_SysInfo*)execute_java_constructor(0,
  474.          "Pdapilot/SysInfo", 0, "()");
  475.     unhand(output)->romVersion = s.romVersion;
  476.     unhand(output)->locale = s.locale;
  477.     unhand(output)->name = makeJavaString(s.name, s.nameLength);
  478.  
  479.     return output;
  480. }
  481.  
  482. extern HPdapilot_DBInfo * Pdapilot_calls_dlp_ReadDBList(struct HPdapilot_calls * self, javaint_t socket, javaint_t card, javaint_t flags, javaint_t start)
  483. {
  484.     HPdapilot_DBInfo * output = NULL;
  485.     struct DBInfo i;
  486.     int result = dlp_ReadDBList(socket, card, flags, start, &i);
  487.     if (result == -5) 
  488.         return 0;
  489.     else if (result < 0) {
  490.         throwDlpException(result);
  491.         return 0;
  492.     }
  493.     
  494.     output = (HPdapilot_DBInfo*)execute_java_constructor(0,
  495.          "Pdapilot/DBInfo", 0, "()");
  496.          
  497.     unhand(output)->flagReadOnly = !!(i.flags & dlpDBFlagReadOnly);
  498.     unhand(output)->flagResource = !!(i.flags & dlpDBFlagResource);
  499.     unhand(output)->flagBackup = !!(i.flags & dlpDBFlagBackup);
  500.     unhand(output)->flagOpen = !!(i.flags & dlpDBFlagOpen);
  501.     unhand(output)->flagAppInfoDirty = !!(i.flags & dlpDBFlagAppInfoDirty);
  502.     unhand(output)->flagNewer = !!(i.flags & dlpDBFlagNewer);
  503.     unhand(output)->flagReset = !!(i.flags & dlpDBFlagReset);
  504.     unhand(output)->flagExcludeFromSync = !!(i.miscFlags & dlpDBMiscFlagExcludeFromSync);
  505.     unhand(output)->index = i.index;
  506.     unhand(output)->version = i.version;
  507.     unhand(output)->modnum = i.modnum;
  508.     unhand(output)->type = makeJavaChar4(i.type);
  509.     unhand(output)->creator = makeJavaChar4(i.creator);
  510.     unhand(output)->createDate = makeJavaDate(i.createDate);
  511.     unhand(output)->modifyDate = makeJavaDate(i.modifyDate);
  512.     unhand(output)->backupDate = makeJavaDate(i.backupDate);
  513.     unhand(output)->name = makeJavaString(i.name, strlen(i.name));
  514.     unhand(output)->card = card;
  515.  
  516.     unhand(output)->more = i.more;
  517.  
  518.     return output;
  519. }
  520.  
  521. extern HPdapilot_UserInfo * Pdapilot_calls_dlp_ReadUserInfo(struct HPdapilot_calls * self, javaint_t socket)
  522. {
  523.     HPdapilot_UserInfo * output = NULL;
  524.     struct PilotUser u;
  525.     int result = dlp_ReadUserInfo(socket, &u);
  526.     if (result < 0) {
  527.         throwDlpException(result);
  528.         return 0;
  529.     }
  530.     output = (HPdapilot_UserInfo*)execute_java_constructor(0,
  531.          "Pdapilot/UserInfo", 0, "()");
  532.     
  533.     unhand(output)->username = makeJavaString(u.username, strlen(u.username));
  534.     unhand(output)->userID = u.userID;
  535.     unhand(output)->viewerID = u.viewerID;
  536.     unhand(output)->lastSyncPC = u.lastSyncPC;
  537.     unhand(output)->password= getByteArray(u.passwordLength);
  538.     memcpy(unhand(unhand(output)->password)->body, u.password, u.passwordLength);
  539.     
  540.     unhand(output)->successfulSyncDate = makeJavaDate(u.successfulSyncDate);
  541.     unhand(output)->lastSyncDate = makeJavaDate(u.lastSyncDate);
  542.  
  543.     return output;
  544. }
  545.  
  546. extern javaint_t Pdapilot_calls_dlp_WriteUserInfo(struct HPdapilot_calls * self, javaint_t socket, HPdapilot_UserInfo * user)
  547. {
  548.     struct PilotUser u;
  549.     int result;
  550.     
  551.     u.userID = unhand(user)->userID;
  552.     u.viewerID = unhand(user)->viewerID;
  553.     u.lastSyncPC = unhand(user)->lastSyncPC;
  554.     u.passwordLength = getArrayLength(unhand(user)->password);
  555.     memcpy(u.password, unhand(unhand(user)->password)->body, u.passwordLength);
  556.     u.successfulSyncDate = readJavaDate(unhand(user)->successfulSyncDate);
  557.     u.lastSyncDate = readJavaDate(unhand(user)->lastSyncDate);
  558.     javaString2CString(unhand(user)->username, u.username, 127);
  559.     
  560.     result = dlp_WriteUserInfo(socket, &u);
  561.     if (result < 0) {
  562.         throwDlpException(result);
  563.     }
  564.     return result;
  565. }
  566.  
  567.  
  568. extern HPdapilot_NetInfo * Pdapilot_calls_dlp_ReadNetSyncInfo(struct HPdapilot_calls * self, javaint_t socket)
  569. {
  570.     HPdapilot_NetInfo * output = NULL;
  571.     struct NetSyncInfo i;
  572.     int result = dlp_ReadNetSyncInfo(socket, &i);
  573.     if (result < 0) {
  574.         throwDlpException(result);
  575.         return 0;
  576.     }
  577.     output = (HPdapilot_NetInfo*)execute_java_constructor(0,
  578.          "Pdapilot/NetInfo", 0, "()");
  579.          
  580.     unhand(output)->lanSync = i.lanSync;
  581.     unhand(output)->hostName = makeJavaString(i.hostName, strlen(i.hostName));
  582.     unhand(output)->hostAddress = makeJavaString(i.hostAddress, strlen(i.hostAddress));
  583.     unhand(output)->hostSubnetMask = makeJavaString(i.hostSubnetMask, strlen(i.hostSubnetMask));
  584.     
  585.     return output;
  586. }
  587.  
  588. extern javaint_t Pdapilot_calls_dlp_WriteNetSyncInfo(struct HPdapilot_calls * self, javaint_t socket, HPdapilot_NetInfo * info)
  589. {
  590.     struct NetSyncInfo i;
  591.     int result;
  592.     
  593.     i.lanSync = unhand(info)->lanSync;
  594.     javaString2CString(unhand(info)->hostName, i.hostName, 256);
  595.     javaString2CString(unhand(info)->hostAddress, i.hostAddress, 40);
  596.     javaString2CString(unhand(info)->hostSubnetMask, i.hostSubnetMask, 40);
  597.     
  598.     result = dlp_WriteNetSyncInfo(socket, &i);
  599.     if (result < 0) {
  600.         throwDlpException(result);
  601.     }
  602.     return result;
  603. }
  604.  
  605. extern javaint_t Pdapilot_calls_dlp_OpenConduit(struct HPdapilot_calls * self, javaint_t socket)
  606. {
  607.     int result = dlp_OpenConduit(socket);
  608.     if (result == dlpErrSync)
  609.         throwCancelSyncException();
  610.     else if (result < 0)
  611.         throwDlpException(result);
  612.     return result;
  613. }
  614.  
  615. extern javaint_t Pdapilot_calls_dlp_CloseDB(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle)
  616. {
  617.     int result;
  618.     result = dlp_CloseDB(socket, handle);
  619.     if (result<0)
  620.         throwDlpException(result);
  621.     return result;
  622. }
  623.  
  624. extern javaint_t Pdapilot_calls_dlp_ResetDBIndex(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle)
  625. {
  626.     int result;
  627.     result = dlp_ResetDBIndex(socket, handle);
  628.     if (result<0)
  629.         throwDlpException(result);
  630.     return result;
  631. }
  632.  
  633. extern Hjava_lang_String * Pdapilot_calls_dlp_strerror(struct HPdapilot_calls *self, javaint_t error)
  634. {
  635.     char * result = dlp_strerror(error);
  636.     if (!result)
  637.         result = "Unknown DLP error";
  638.     return makeJavaString(result, strlen(result));
  639. }
  640.  
  641. extern HPdapilot_Record * Pdapilot_calls_dlp_ReadRecordByIndex(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t index, HPdapilot_Database * dbClass)
  642. {
  643.     int attr, cat;
  644.     recordid_t id;
  645.     char * buffer = malloc(0xffff);
  646.     int len;
  647.     HPdapilot_Record * output = NULL;
  648.     
  649.     int result = dlp_ReadRecordByIndex(socket, handle, index, buffer, &id, &len, &attr, &cat);
  650.     
  651.     if (result >= 0) {
  652.         HArrayOfByte * a = getByteArray(len);
  653.         memcpy(unhand(a)->body, buffer, len);
  654.         output = (HPdapilot_Record*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  655.             "newRecord", "([BLPdapilot/RecordID;III)LPdapilot/Record;",
  656.             a, makeJavaRecordID(id), (javaint_t)index, (javaint_t)attr, (javaint_t)cat);
  657.     } else if (result != -5) {
  658.         throwDlpException(result);
  659.     }
  660.     
  661.     free(buffer);
  662.     
  663.     return output;
  664. }
  665.  
  666. extern HArrayOfByte * Pdapilot_calls_dlp_CallApplication(struct HPdapilot_calls * self, javaint_t socket, HPdapilot_Char4 * creator, javaint_t type, javaint_t action, HArrayOfByte * outgoing_data, HArrayOfInt * retcode)
  667. {
  668.     char * buffer = malloc(0xffff);
  669.     int len;
  670.     unsigned long ret;
  671.     HArrayOfByte * incoming_data = 0;
  672.         
  673.     int result = dlp_CallApplication(socket, getJavaChar4(creator), type, action, getArrayLength(outgoing_data), unhand(outgoing_data)->body, &ret, 0xffff, &len, buffer);
  674.     
  675.     if (result >= 0) {
  676.         incoming_data = getByteArray(len);
  677.         memcpy(unhand(incoming_data)->body, buffer, len);
  678.         unhand(retcode)->body[0] = ret;
  679.     } else if (result != -5) {
  680.         throwDlpException(result);
  681.     }
  682.     
  683.     free(buffer);
  684.     
  685.     return incoming_data;
  686. }
  687.  
  688. extern HPdapilot_Record * Pdapilot_calls_dlp_ReadNextModifiedRec(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_Database * dbClass)
  689. {
  690.     int attr, cat, index;
  691.     recordid_t id;
  692.     char * buffer = malloc(0xffff);
  693.     int len;
  694.     HPdapilot_Record * output = NULL;
  695.     
  696.     int result = dlp_ReadNextModifiedRec(socket, handle, buffer, &id, &index, &len, &attr, &cat);
  697.     
  698.     if (result >= 0) {
  699.         HArrayOfByte * a = getByteArray(len);
  700.         memcpy(unhand(a)->body, buffer, len);
  701.         output = (HPdapilot_Record*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  702.             "newRecord", "([BLPdapilot/RecordID;III)LPdapilot/Record;",
  703.             a, makeJavaRecordID(id), (javaint_t)index, (javaint_t)attr, (javaint_t)cat);
  704.     } else if (result != -5) {
  705.         throwDlpException(result);
  706.     }
  707.     
  708.     free(buffer);
  709.     
  710.     return output;
  711. }
  712.  
  713. extern HPdapilot_Record * Pdapilot_calls_dlp_ReadNextModifiedRecInCategory(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t cat, HPdapilot_Database * dbClass)
  714. {
  715.     int attr, index;
  716.     recordid_t id;
  717.     char * buffer = malloc(0xffff);
  718.     int len;
  719.     HPdapilot_Record * output = NULL;
  720.     
  721.     int result = dlp_ReadNextModifiedRecInCategory(socket, handle, cat, buffer, &id, &index, &len, &attr);
  722.     
  723.     if (result >= 0) {
  724.         HArrayOfByte * a = getByteArray(len);
  725.         memcpy(unhand(a)->body, buffer, len);
  726.         output = (HPdapilot_Record*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  727.             "newRecord", "([BLPdapilot/RecordID;III)LPdapilot/Record;",
  728.             a, makeJavaRecordID(id), (javaint_t)index, (javaint_t)attr, (javaint_t)cat);
  729.     } else if (result != -5) {
  730.         throwDlpException(result);
  731.     }
  732.     
  733.     free(buffer);
  734.     
  735.     return output;
  736. }
  737.  
  738. extern HPdapilot_Record * Pdapilot_calls_dlp_ReadNextRecInCategory(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t cat, HPdapilot_Database * dbClass)
  739. {
  740.     int attr, index;
  741.     recordid_t id;
  742.     char * buffer = malloc(0xffff);
  743.     int len;
  744.     HPdapilot_Record * output = NULL;
  745.     
  746.     int result = dlp_ReadNextRecInCategory(socket, handle, cat, buffer, &id, &index, &len, &attr);
  747.     
  748.     if (result >= 0) {
  749.         HArrayOfByte * a = getByteArray(len);
  750.         memcpy(unhand(a)->body, buffer, len);
  751.         output = (HPdapilot_Record*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  752.             "newRecord", "([BLPdapilot/RecordID;III)LPdapilot/Record;",
  753.             a, makeJavaRecordID(id), (javaint_t)index, (javaint_t)attr, (javaint_t)cat);
  754.     } else if (result != -5) {
  755.         throwDlpException(result);
  756.     }
  757.     
  758.     free(buffer);
  759.     
  760.     return output;
  761. }
  762.  
  763. extern HPdapilot_AppBlock * Pdapilot_calls_dlp_ReadAppBlock(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_Database * dbClass)
  764. {
  765.     char * buffer = malloc(0xffff);
  766.     int len;
  767.     HPdapilot_AppBlock * output = NULL;
  768.     
  769.     int result = dlp_ReadAppBlock(socket, handle, 0, buffer, 0xffff);
  770.     
  771.     if (result >= 0) {
  772.         HArrayOfByte * a;
  773.         len = result;
  774.         a = getByteArray(len);
  775.         memcpy(unhand(a)->body, buffer, len);
  776.         output = (HPdapilot_AppBlock*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  777.             "newAppBlock", "([B)LPdapilot/AppBlock;",
  778.             a);
  779.     } else if (result != -5) {
  780.         throwDlpException(result);
  781.     }
  782.     
  783.     free(buffer);
  784.     
  785.     return output;
  786. }
  787.  
  788. extern HPdapilot_Pref * Pdapilot_calls_dlp_ReadAppPreference(struct HPdapilot_calls * self, javaint_t socket, HPdapilot_Char4 * creator, javaint_t id, javaint_t backup, HPdapilot_Database * dbClass)
  789. {
  790.     char * buffer = malloc(0xffff);
  791.     int len, version;
  792.     HPdapilot_Pref * output = NULL;
  793.     
  794.     int result = dlp_ReadAppPreference(socket, getJavaChar4(creator), id, backup, 0xffff, buffer, &len, &version);
  795.     
  796.     if (result >= 0) {
  797.         HArrayOfByte * a;
  798.         a = getByteArray(len);
  799.         memcpy(unhand(a)->body, buffer, len);
  800.         output = (HPdapilot_Pref*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  801.             "newPref", "([BLPdapilot/Char4;IIZ)LPdapilot/Pref;",
  802.             a, creator, id, version, backup);
  803.     } else if (result != -5) {
  804.         throwDlpException(result);
  805.     }
  806.     
  807.     free(buffer);
  808.     
  809.     return output;
  810. }
  811.  
  812. extern javaint_t Pdapilot_calls_dlp_ReadFeature(struct HPdapilot_calls * self, javaint_t socket, HPdapilot_Char4 * creator, javaint_t id)
  813. {
  814.     long feature;
  815.     
  816.     int result = dlp_ReadFeature(socket, getJavaChar4(creator), id, &feature);
  817.     
  818.     if (result < 0)
  819.         throwDlpException(result);
  820.     
  821.     return feature;
  822. }
  823.  
  824. extern HArrayOfObject * Pdapilot_calls_dlp_ReadRecordIDList(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t sort, javaint_t start, javaint_t max)
  825. {
  826.     recordid_t * l = malloc(sizeof(recordid_t)*max);
  827.     int count;
  828.     int result;
  829.     HArrayOfObject * output = 0;
  830.     int i;
  831.     
  832.     result = dlp_ReadRecordIDList(socket, handle, sort, start, max, l, &count);
  833.     
  834.     if (result < 0)
  835.         throwDlpException(result);
  836.     else {
  837.         output = makeRecordIDArray(count);
  838.         if (output) {
  839.             for (i=0;i<count;i++) {
  840.                 unhand(output)->body[i] = (HObject*)makeJavaRecordID(l[i]);
  841.             }
  842.         }
  843.     }
  844.         
  845.     free(l);
  846.     
  847.     return output;
  848. }
  849.  
  850. extern HPdapilot_SortBlock * Pdapilot_calls_dlp_ReadSortBlock(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_Database * dbClass)
  851. {
  852.     char * buffer = malloc(0xffff);
  853.     int len;
  854.     HPdapilot_SortBlock * output = NULL;
  855.     
  856.     int result = dlp_ReadSortBlock(socket, handle, 0, buffer, 0xffff);
  857.     
  858.     if (result >= 0) {
  859.         HArrayOfByte * a;
  860.         len = result;
  861.         a = getByteArray(len);
  862.         memcpy(unhand(a)->body, buffer, len);
  863.         output = (HPdapilot_SortBlock*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  864.             "newSortBlock", "([B)LPdapilot/SortBlock;",
  865.             a);
  866.     } else if (result != -5) {
  867.         throwDlpException(result);
  868.     }
  869.     
  870.     free(buffer);
  871.     
  872.     return output;
  873. }
  874.  
  875. extern HPdapilot_Record * Pdapilot_calls_dlp_ReadRecordByID(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_RecordID * id, HPdapilot_Database * dbClass)
  876. {
  877.     int attr, cat;
  878.     char * buffer = malloc(0xffff);
  879.     int len;
  880.     int index;
  881.     HPdapilot_Record * output = NULL;
  882.     
  883.     int result = dlp_ReadRecordById(socket, handle, getJavaRecordID(id), buffer, &index, &len, &attr, &cat);
  884.     
  885.     if (result >= 0) {
  886.         HArrayOfByte * a = getByteArray(len);
  887.         memcpy(unhand(a)->body, buffer, len);
  888.         output = (HPdapilot_Record*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  889.             "newRecord", "([BLPdapilot/RecordID;III)LPdapilot/Record;",
  890.             a, id, (javaint_t)index, (javaint_t)attr, (javaint_t)cat);
  891.     } else if (result != -5) {
  892.         throwDlpException(result);
  893.     }
  894.     
  895.     free(buffer);
  896.     
  897.     return output;
  898. }
  899.  
  900. extern HPdapilot_Resource * Pdapilot_calls_dlp_ReadResourceByType(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_Char4 * type, javaint_t id, HPdapilot_Database * dbClass)
  901. {
  902.     char * buffer = malloc(0xffff);
  903.     int len;
  904.     int index;
  905.     HPdapilot_Resource * output = NULL;
  906.     
  907.     int result = dlp_ReadResourceByType(socket, handle, unhand(type)->value, id, buffer, &index, &len);
  908.     
  909.     if (result >= 0) {
  910.         HArrayOfByte * a = getByteArray(len);
  911.         memcpy(unhand(a)->body, buffer, len);
  912.         output = (HPdapilot_Resource*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  913.             "newResource", "([BLPdapilot/Char4;II)LPdapilot/Resource;",
  914.             a, type, (javaint_t)id, (javaint_t)index);
  915.     } else if (result != -5) {
  916.         throwDlpException(result);
  917.     }
  918.     
  919.     free(buffer);
  920.     
  921.     return output;
  922. }
  923.  
  924. extern HPdapilot_Resource * Pdapilot_calls_dlp_ReadResourceByIndex(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, javaint_t index, HPdapilot_Database * dbClass)
  925. {
  926.     long type;
  927.     char * buffer = malloc(0xffff);
  928.     int len, id;
  929.     HPdapilot_Resource * output = NULL;
  930.     
  931.     int result = dlp_ReadResourceByIndex(socket, handle, index, buffer, &type, &id, &len);
  932.     
  933.     if (result >= 0) {
  934.         HArrayOfByte * a = getByteArray(len);
  935.  
  936.         memcpy(unhand(a)->body, buffer, len);
  937.         output = (HPdapilot_Resource*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  938.             "newResource", "([BLPdapilot/Char4;II)LPdapilot/Resource;",
  939.             a, makeJavaChar4(type), (javaint_t)id, (javaint_t)index);
  940.     } else if (result != -5) {
  941.         throwDlpException(result);
  942.     }
  943.     
  944.     free(buffer);
  945.     
  946.     return output;
  947. }
  948.  
  949. extern javaint_t Pdapilot_calls_dlp_WriteRecord(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_Record * record)
  950. {
  951.     int attr, cat;
  952.     HArrayOfByte * b;
  953.     char * buffer;
  954.     int len;
  955.     recordid_t id;
  956.     int result;
  957.     
  958.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)record, "pack", "()[B");
  959.     if (!b)
  960.         return 0;
  961.     
  962.     id = getJavaRecordID(unhand(record)->id);
  963.     attr = 0;
  964.     attr |= unhand(record)->deleted ? 0x80 : 0;
  965.     attr |= unhand(record)->modified ? 0x40 : 0;
  966.     attr |= unhand(record)->busy ? 0x20 : 0;
  967.     attr |= unhand(record)->secret ? 0x10 : 0;
  968.     attr |= unhand(record)->archived ? 0x08 : 0;
  969.     cat = unhand(record)->category;
  970.     buffer = unhand(b)->body;
  971.     len = getArrayLength(b);
  972.     
  973.     result = dlp_WriteRecord(socket, handle, attr, id, cat, buffer, len, &id);
  974.     
  975.     if (result >= 0) {
  976.         return id;
  977.     } else  {
  978.         throwDlpException(result);
  979.     }
  980.     
  981.     return 0;
  982. }
  983.  
  984. extern javaint_t Pdapilot_calls_dlp_WriteAppPreference(struct HPdapilot_calls * self, javaint_t socket, HPdapilot_Pref * pref)
  985. {
  986.     HArrayOfByte * b;
  987.     char * buffer;
  988.     int len;
  989.     javaint_t creator;
  990.     int id, version;
  991.     int result;
  992.     int backup;
  993.     
  994.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)pref, "pack", "()[B");
  995.     if (!b)
  996.         return 0;
  997.     
  998.     creator = getJavaChar4(unhand(pref)->creator);
  999.     id = unhand(pref)->id;
  1000.     version = unhand(pref)->version;
  1001.     backup = unhand(pref)->backup;
  1002.     buffer = unhand(b)->body;
  1003.     len = getArrayLength(b);
  1004.     
  1005.     result = dlp_WriteAppPreference(socket, creator, id, backup, version, buffer, len);
  1006.     
  1007.     if (result < 0)
  1008.         throwDlpException(result);
  1009.     
  1010.     return result;
  1011. }
  1012.  
  1013. extern javaint_t Pdapilot_calls_dlp_WriteAppBlock(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_AppBlock * appblock)
  1014. {
  1015.     HArrayOfByte * b;
  1016.     char * buffer;
  1017.     int len;
  1018.     int result;
  1019.     
  1020.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)appblock, "pack", "()[B");
  1021.     if (!b)
  1022.         return 0;
  1023.     
  1024.     buffer = unhand(b)->body;
  1025.     len = getArrayLength(b);
  1026.     
  1027.     result = dlp_WriteAppBlock(socket, handle, buffer, len);
  1028.     
  1029.     if (result < 0)
  1030.         throwDlpException(result);
  1031.     
  1032.     return result;
  1033. }
  1034.  
  1035. extern javaint_t Pdapilot_calls_dlp_WriteSortBlock(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_SortBlock * sortblock)
  1036. {
  1037.     HArrayOfByte * b;
  1038.     char * buffer;
  1039.     int len;
  1040.     int result;
  1041.     
  1042.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)sortblock, "pack", "()[B");
  1043.     if (!b)
  1044.         return 0;
  1045.     
  1046.     buffer = unhand(b)->body;
  1047.     len = getArrayLength(b);
  1048.     
  1049.     result = dlp_WriteSortBlock(socket, handle, buffer, len);
  1050.     
  1051.     if (result < 0)
  1052.         throwDlpException(result);
  1053.     
  1054.     return result;
  1055. }
  1056.  
  1057. extern javaint_t Pdapilot_calls_dlp_WriteResource(struct HPdapilot_calls * self, javaint_t socket, javaint_t handle, HPdapilot_Resource * resource)
  1058. {
  1059.     char * buffer;
  1060.     HArrayOfByte * b;
  1061.     int len;
  1062.     javaint_t type;
  1063.     javaint_t id;
  1064.     int result;
  1065.  
  1066.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)resource, "pack", "()[B");
  1067.     if (!b)
  1068.         return 0;
  1069.     
  1070.     type = unhand(unhand(resource)->type)->value;
  1071.     id = unhand(resource)->id;
  1072.     buffer = unhand(b)->body;
  1073.     len = getArrayLength(b);
  1074.     
  1075.     result = dlp_WriteResource(socket, handle, type, id, buffer, len);
  1076.     
  1077.     if (result < 0)
  1078.         throwDlpException(result);
  1079.     
  1080.     return result;
  1081. }
  1082.  
  1083.  
  1084. extern void Pdapilot_memo_Record_unpack(struct HPdapilot_memo_Record * self,  struct HArrayOfByte *b)
  1085. {
  1086.     struct Memo m;
  1087.     unpack_Memo(&m, unhand(b)->body, getArrayLength(b));
  1088.     
  1089.     unhand(self)->raw = b;
  1090.     
  1091.     unhand(self)->text = m.text ? makeJavaString(m.text, strlen(m.text)) : 0;
  1092.     free_Memo(&m);
  1093. }
  1094.  
  1095. extern HArrayOfByte* Pdapilot_memo_Record_pack(struct HPdapilot_memo_Record * self){
  1096.     char * buffer = malloc(0xffff);
  1097.     int len;
  1098.     HArrayOfByte * output;
  1099.     
  1100.     struct Memo m;
  1101.     
  1102.     m.text = makeCString(unhand(self)->text);
  1103.     len = pack_Memo(&m, buffer, 0xffff);
  1104.     
  1105.     output = getByteArray(len);
  1106.     memcpy(unhand(output)->body, buffer, len);
  1107.     
  1108.     unhand(self)->raw = output;
  1109.     
  1110.     free(buffer);
  1111.     
  1112.     return output;
  1113. }
  1114.  
  1115. static void doUnpackCategories(HPdapilot_CategoryAppBlock * self, struct CategoryAppInfo * c)
  1116. {
  1117.     int i;
  1118.     unhand(self)->categoryLastUniqueID = c->lastUniqueID;
  1119.     if (!(unhand(self)->categoryName = makeStringArray(16)))
  1120.         return;
  1121.     if (!(unhand(self)->categoryID = makeIntArray(16)))
  1122.         return;
  1123.     if (!(unhand(self)->categoryRenamed = makeIntArray(16)))
  1124.         return;
  1125.     
  1126.     for (i=0;i<16;i++) {
  1127.         unhand(unhand(self)->categoryName)->body[i] = (HObject*)makeJavaString(c->name[i], strlen(c->name[i]));
  1128.         unhand(unhand(self)->categoryID)->body[i] = c->ID[i];
  1129.         unhand(unhand(self)->categoryRenamed)->body[i] = c->renamed[i];
  1130.     }
  1131. }
  1132.  
  1133. static void doPackCategories(HPdapilot_CategoryAppBlock * self, struct CategoryAppInfo * c)
  1134. {
  1135.     int i;
  1136.     c->lastUniqueID = unhand(self)->categoryLastUniqueID;
  1137.  
  1138.     for (i=0;i<16;i++) {
  1139.         javaString2CString((HString*)unhand(unhand(self)->categoryName)->body[i], c->name[i], 16);
  1140.         c->ID[i] = unhand(unhand(self)->categoryID)->body[i];
  1141.         c->renamed[i] = unhand(unhand(self)->categoryRenamed)->body[i];
  1142.     }
  1143. }
  1144.  
  1145. extern void Pdapilot_memo_AppBlock_unpack(struct HPdapilot_memo_AppBlock * self,  struct HArrayOfByte *b)
  1146. {
  1147.     struct MemoAppInfo m;
  1148.  
  1149.     unpack_MemoAppInfo(&m, unhand(b)->body, getArrayLength(b));
  1150.     
  1151.     unhand(self)->raw = b;
  1152.  
  1153.     doUnpackCategories((HPdapilot_CategoryAppBlock*)self, &m.category);
  1154.     
  1155.     unhand(self)->sortByAlpha = m.sortByAlpha;
  1156. }
  1157.  
  1158. extern HArrayOfByte* Pdapilot_memo_AppBlock_pack(struct HPdapilot_memo_AppBlock * self){
  1159.     char * buffer = malloc(0xffff);
  1160.     int len;
  1161.     HArrayOfByte * output;
  1162.     
  1163.     struct MemoAppInfo m;
  1164.  
  1165.     doPackCategories((HPdapilot_CategoryAppBlock*)self, &m.category);
  1166.     
  1167.     m.sortByAlpha = unhand(self)->sortByAlpha;
  1168.  
  1169.     len = pack_MemoAppInfo(&m, buffer, 0xffff);
  1170.     
  1171.     output = getByteArray(len);
  1172.     memcpy(unhand(output)->body, buffer, len);
  1173.     
  1174.     unhand(self)->raw = output;
  1175.     
  1176.     free(buffer);
  1177.     
  1178.     return output;
  1179. }
  1180.  
  1181.  
  1182. extern void Pdapilot_todo_Record_unpack(struct HPdapilot_todo_Record * self,  struct HArrayOfByte *b)
  1183. {
  1184.     struct ToDo t;
  1185.     unpack_ToDo(&t, unhand(b)->body, getArrayLength(b));
  1186.     
  1187.     unhand(self)->raw = b;
  1188.     
  1189.     unhand(self)->due = t.indefinite ? makeJavaDateTm(&t.due) : 0;
  1190.     unhand(self)->priority = t.priority;
  1191.     unhand(self)->complete = t.complete;
  1192.     unhand(self)->description = t.description ? makeJavaString(t.description, strlen(t.description)) : 0;
  1193.     unhand(self)->note = t.note ? makeJavaString(t.note, strlen(t.note)) : 0;
  1194.     
  1195.     free_ToDo(&t);
  1196. }
  1197.  
  1198.  
  1199. extern HArrayOfByte* Pdapilot_todo_Record_pack(struct HPdapilot_todo_Record * self){
  1200.     char * buffer = malloc(0xffff);
  1201.     int len;
  1202.     HArrayOfByte * output;
  1203.     
  1204.     struct ToDo t;
  1205.     
  1206.     struct tm * tm;
  1207.     
  1208.     t.description = unhand(self)->description ? makeCString(unhand(self)->description) : 0;
  1209.     t.note = unhand(self)->note ? makeCString(unhand(self)->note) : 0;
  1210.     t.priority = unhand(self)->priority;
  1211.     t.complete = unhand(self)->complete;
  1212.     t.indefinite = 1;
  1213.     if (unhand(self)->due) {
  1214.         tm = readJavaDateTm(unhand(self)->due);
  1215.         if (tm) {
  1216.             t.due = *tm;
  1217.             t.indefinite = 0;
  1218.         }
  1219.     }
  1220.     
  1221.     len = pack_ToDo(&t, buffer, 0xffff);
  1222.     
  1223.     output = getByteArray(len);
  1224.     memcpy(unhand(output)->body, buffer, len);
  1225.     
  1226.     unhand(self)->raw = output;
  1227.     
  1228.     free(buffer);
  1229.     
  1230.     return output;
  1231. }
  1232.  
  1233. extern void Pdapilot_todo_AppBlock_unpack(struct HPdapilot_todo_AppBlock * self,  struct HArrayOfByte *b)
  1234. {
  1235.     struct ToDoAppInfo t;
  1236.  
  1237.     unpack_ToDoAppInfo(&t, unhand(b)->body, getArrayLength(b));
  1238.     
  1239.     unhand(self)->raw = b;
  1240.  
  1241.     doUnpackCategories((HPdapilot_CategoryAppBlock*)self, &t.category);
  1242.     
  1243.     unhand(self)->dirty = t.dirty;
  1244.     unhand(self)->sortByPriority = t.sortByPriority;
  1245. }
  1246.  
  1247. extern HArrayOfByte* Pdapilot_todo_AppBlock_pack(struct HPdapilot_todo_AppBlock * self){
  1248.     char * buffer = malloc(0xffff);
  1249.     int len;
  1250.     HArrayOfByte * output;
  1251.     
  1252.     struct ToDoAppInfo t;
  1253.     
  1254.     t.sortByPriority = unhand(self)->sortByPriority;
  1255.     t.dirty = unhand(self)->dirty;
  1256.  
  1257.     doPackCategories((HPdapilot_CategoryAppBlock*)self, &t.category);
  1258.     
  1259.     len = pack_ToDoAppInfo(&t, buffer, 0xffff);
  1260.     
  1261.     output = getByteArray(len);
  1262.     memcpy(unhand(output)->body, buffer, len);
  1263.     
  1264.     unhand(self)->raw = output;
  1265.     
  1266.     free(buffer);
  1267.     
  1268.     return output;
  1269. }
  1270.  
  1271. extern void Pdapilot_CategoryAppBlock_unpack(struct HPdapilot_CategoryAppBlock * self,  struct HArrayOfByte *b)
  1272. {
  1273.     struct CategoryAppInfo c;
  1274.  
  1275.     unpack_CategoryAppInfo(&c, unhand(b)->body, getArrayLength(b));
  1276.     
  1277.     unhand(self)->raw = b;
  1278.  
  1279.  
  1280.     doUnpackCategories(self, &c);
  1281. }
  1282.  
  1283. extern HArrayOfByte* Pdapilot_CategoryAppBlock_pack(struct HPdapilot_CategoryAppBlock * self){
  1284.     char * buffer = malloc(0xffff);
  1285.     int len;
  1286.     HArrayOfByte * output;
  1287.     
  1288.     struct CategoryAppInfo c;
  1289.     
  1290.     doPackCategories(self, &c);
  1291.     
  1292.     len = pack_CategoryAppInfo(&c, buffer, 0xffff);
  1293.     
  1294.     output = getByteArray(len);
  1295.     memcpy(unhand(output)->body, buffer, len);
  1296.     
  1297.     unhand(self)->raw = output;
  1298.     
  1299.     free(buffer);
  1300.     
  1301.     return output;
  1302. }
  1303.  
  1304.  
  1305. extern void Pdapilot_address_Record_unpack(struct HPdapilot_address_Record * self,  struct HArrayOfByte *b)
  1306. {
  1307.     struct Address a;
  1308.     int i;
  1309.     unpack_Address(&a, unhand(b)->body, getArrayLength(b));
  1310.     
  1311.     
  1312.     unhand(self)->raw = b;
  1313.     
  1314.     unhand(self)->showPhone = a.showPhone;
  1315.  
  1316.     if (!(unhand(self)->entry = makeStringArray(19)))
  1317.         return;
  1318.     if (!(unhand(self)->phoneLabel = makeIntArray(5)))
  1319.         return;
  1320.  
  1321.     for (i=0;i<19;i++)
  1322.         unhand(unhand(self)->entry)->body[i] = a.entry[i] ? (HObject*)makeJavaString(a.entry[i], strlen(a.entry[i])) : 0;
  1323.  
  1324.     for (i=0;i<5;i++)
  1325.         unhand(unhand(self)->phoneLabel)->body[i] = a.phoneLabel[i];
  1326.  
  1327.     free_Address(&a);
  1328. }
  1329.  
  1330.  
  1331. extern HArrayOfByte* Pdapilot_address_Record_pack(struct HPdapilot_address_Record * self){
  1332.     char * buffer = malloc(0xffff);
  1333.     int len;
  1334.     int i;
  1335.     HArrayOfByte * output;
  1336.     
  1337.     struct Address a;
  1338.  
  1339.     for (i=0;i<19;i++)
  1340.         javaString2CString((HString*)unhand(unhand(self)->entry)->body[i], a.entry[i], 16);
  1341.  
  1342.     for (i=0;i<5;i++)
  1343.         a.phoneLabel[i] = unhand(unhand(self)->phoneLabel)->body[i];
  1344.     
  1345.     a.showPhone = unhand(self)->showPhone;
  1346.     
  1347.     len = pack_Address(&a, buffer, 0xffff);
  1348.     
  1349.     output = getByteArray(len);
  1350.     memcpy(unhand(output)->body, buffer, len);
  1351.     
  1352.     unhand(self)->raw = output;
  1353.     
  1354.     free(buffer);
  1355.     
  1356.     return output;
  1357. }
  1358.  
  1359. extern void Pdapilot_address_AppBlock_unpack(struct HPdapilot_address_AppBlock * self,  struct HArrayOfByte *b)
  1360. {
  1361.     struct AddressAppInfo a;
  1362.     int i;
  1363.  
  1364.     unpack_AddressAppInfo(&a, unhand(b)->body, getArrayLength(b));
  1365.     
  1366.     unhand(self)->raw = b;
  1367.  
  1368.     doUnpackCategories((HPdapilot_CategoryAppBlock*)self, &a.category);
  1369.     
  1370.     if (!(unhand(self)->labelRenamed = makeIntArray(22)))
  1371.         return;
  1372.     for(i=0;i<22;i++)
  1373.         unhand(unhand(self)->labelRenamed)->body[i] = a.labelRenamed[i];
  1374.     unhand(self)->sortByCompany = a.sortByCompany;
  1375.  
  1376.     if (!(unhand(self)->label = makeStringArray(22)))
  1377.         return;
  1378.     if (!(unhand(self)->phoneLabel = makeStringArray(8)))
  1379.         return;
  1380.     
  1381.     for (i=0;i<22;i++)
  1382.         unhand(unhand(self)->label)->body[i] = (HObject*)makeJavaString(a.labels[i], strlen(a.labels[i]));
  1383.     for (i=0;i<8;i++)
  1384.         unhand(unhand(self)->phoneLabel)->body[i] = (HObject*)makeJavaString(a.phoneLabels[i], strlen(a.phoneLabels[i]));
  1385.  
  1386. }
  1387.  
  1388. extern HArrayOfByte* Pdapilot_address_AppBlock_pack(struct HPdapilot_address_AppBlock * self){
  1389.     char * buffer = malloc(0xffff);
  1390.     int len;
  1391.     int i;
  1392.     HArrayOfByte * output;
  1393.     
  1394.     struct AddressAppInfo a;
  1395.     
  1396.     a.sortByCompany = unhand(self)->sortByCompany;
  1397.     for(i=0;i<22;i++)
  1398.         a.labelRenamed[i] = unhand(unhand(self)->labelRenamed)->body[i];
  1399.  
  1400.     doPackCategories((HPdapilot_CategoryAppBlock*)self, &a.category);
  1401.  
  1402.     for (i=0;i<22;i++)
  1403.         javaString2CString((HString*)unhand(unhand(self)->label)->body[i], a.labels[i], 16);
  1404.  
  1405.     for (i=0;i<8;i++)
  1406.         javaString2CString((HString*)unhand(unhand(self)->phoneLabel)->body[i], a.phoneLabels[i], 16);
  1407.     
  1408.     len = pack_AddressAppInfo(&a, buffer, 0xffff);
  1409.     
  1410.     output = getByteArray(len);
  1411.     memcpy(unhand(output)->body, buffer, len);
  1412.     
  1413.     unhand(self)->raw = output;
  1414.     
  1415.     free(buffer);
  1416.     
  1417.     return output;
  1418. }
  1419.  
  1420.  
  1421. extern void Pdapilot_appointment_Record_unpack(struct HPdapilot_appointment_Record * self,  struct HArrayOfByte *b)
  1422. {
  1423.     struct Appointment a;
  1424.     int i;
  1425.     unpack_Appointment(&a, unhand(b)->body, getArrayLength(b));
  1426.     
  1427.     unhand(self)->note = a.note ? makeJavaString(a.note, strlen(a.note)) : 0;
  1428.     unhand(self)->description = a.description ? makeJavaString(a.description, strlen(a.description)) : 0;
  1429.  
  1430.     unhand(self)->begin = makeJavaDateTm(&a.begin);
  1431.     unhand(self)->end = a.event ? 0 : makeJavaDateTm(&a.end);
  1432.  
  1433.     unhand(self)->alarm = a.alarm;
  1434.     unhand(self)->advance = a.advance;
  1435.     unhand(self)->advanceUnits = (HPdapilot_appointment_time*)
  1436.         execute_java_static_method(0, FindClass(0, "Pdapilot/appointment/time",1),
  1437.         "get", "(I)LPdapilot/appointment/time;", (long)a.advanceUnits);
  1438.     if (!unhand(self)->advanceUnits)
  1439.         return;
  1440.     /*(a.advanceUnits == 0) ? 60 : (a.advanceUnits == 1) ? 60*60 : (a.advanceUnits == 2) ? 60*60*26 : 0;*/
  1441.  
  1442.     if (a.exceptions) {
  1443.         if (!(unhand(self)->exceptions = makeDateArray(a.exceptions)))
  1444.             return;
  1445.         for(i=0;i<a.exceptions;i++)
  1446.             unhand(unhand(self)->exceptions)->body[i] = (HObject*)makeJavaDateTm(&a.exception[i]);
  1447.     }
  1448.  
  1449.     unhand(self)->repeatDay = a.repeatDay;
  1450.     unhand(self)->repeatWeekStart = a.repeatWeekstart;
  1451.     /*unhand(self)->repeatType = a.repeatType;*/
  1452.  
  1453.     unhand(self)->repeatType = (HPdapilot_appointment_repeat*)
  1454.         execute_java_static_method(0, FindClass(0, "Pdapilot/appointment/repeat",1),
  1455.         "get", "(I)LPdapilot/appointment/repeat;", (long)a.repeatType);
  1456.     if (!unhand(self)->repeatType)
  1457.         return;
  1458.  
  1459.     if (!(unhand(self)->repeatWeekdays = makeIntArray(7)))
  1460.         return;
  1461.     for(i=0;i<7;i++)
  1462.         unhand(unhand(self)->repeatWeekdays)->body[i] = a.repeatDays[i];
  1463.  
  1464.     unhand(self)->repeatEnd = a.repeatForever ? 0 : makeJavaDateTm(&a.repeatEnd);
  1465.  
  1466.     free_Appointment(&a);
  1467. }
  1468.  
  1469. extern HArrayOfByte* Pdapilot_appointment_Record_pack(struct HPdapilot_appointment_Record * self){
  1470.     char * buffer = malloc(0xffff);
  1471.     int len;
  1472.     int i;
  1473.     HArrayOfByte * output;
  1474.     
  1475.     struct Appointment a;
  1476.  
  1477.     a.note = unhand(self)->note ? makeCString(unhand(self)->note) : 0;
  1478.     a.description = unhand(self)->description ? makeCString(unhand(self)->description) : 0;
  1479.     
  1480.     a.begin = *readJavaDateTm(unhand(self)->begin);
  1481.     if (unhand(self)->end) {
  1482.         a.end = *readJavaDateTm(unhand(self)->end);
  1483.         a.event = 1;
  1484.     } else {
  1485.         a.event = 0;
  1486.     }
  1487.  
  1488.     a.alarm = unhand(self)->alarm;
  1489.     a.advance = unhand(self)->advance;
  1490.     a.advanceUnits = (long)execute_java_dynamic_method(0, (HObject*)unhand(self)->advanceUnits, 
  1491.             "getValue", "()I");
  1492.     
  1493.     a.repeatType = (long)execute_java_dynamic_method(0, (HObject*)unhand(self)->repeatType, 
  1494.             "getValue", "()I");
  1495.     
  1496.     if (a.repeatType == repeatWeekly) {
  1497.         for(i=0;i<7;i++)
  1498.             a.repeatDays[i] = unhand(unhand(self)->repeatWeekdays)->body[i];
  1499.     } else {
  1500.         a.repeatDay = unhand(self)->repeatDay;
  1501.     }
  1502.     a.repeatWeekstart = unhand(self)->repeatWeekStart;
  1503.     
  1504.     if (unhand(self)->repeatEnd) {
  1505.         a.repeatForever = 0;
  1506.         a.repeatEnd = *readJavaDateTm(unhand(self)->repeatEnd);
  1507.     } else
  1508.         a.repeatForever = 1;
  1509.     if (unhand(self)->exceptions) {
  1510.         a.exceptions = getObjectArrayLength(unhand(self)->exceptions);
  1511.         a.exception = malloc(sizeof(struct tm)*a.exceptions);
  1512.         for(i=0;i<a.exceptions;i++)
  1513.             a.exception[i] = *readJavaDateTm((Hjava_util_Date*)unhand(unhand(self)->exceptions)->body[i]);
  1514.     }
  1515.     
  1516.     len = pack_Appointment(&a, buffer, 0xffff);
  1517.     
  1518.     output = getByteArray(len);
  1519.     memcpy(unhand(output)->body, buffer, len);
  1520.     
  1521.     unhand(self)->raw = output;
  1522.     
  1523.     free(buffer);
  1524.     
  1525.     return output;
  1526. }
  1527.  
  1528. extern void Pdapilot_appointment_AppBlock_unpack(struct HPdapilot_appointment_AppBlock * self,  struct HArrayOfByte *b)
  1529. {
  1530.     struct AppointmentAppInfo a;
  1531.  
  1532.     unpack_AppointmentAppInfo(&a, unhand(b)->body, getArrayLength(b));
  1533.     
  1534.     unhand(self)->raw = b;
  1535.  
  1536.     doUnpackCategories((HPdapilot_CategoryAppBlock*)self, &a.category);
  1537.     
  1538.     unhand(self)->startOfWeek = a.startOfWeek;
  1539. }
  1540.  
  1541. extern HArrayOfByte* Pdapilot_appointment_AppBlock_pack(struct HPdapilot_appointment_AppBlock * self){
  1542.     char * buffer = malloc(0xffff);
  1543.     int len;
  1544.     HArrayOfByte * output;
  1545.     
  1546.     struct AppointmentAppInfo a;
  1547.     
  1548.     a.startOfWeek = unhand(self)->startOfWeek;
  1549.  
  1550.     doPackCategories((HPdapilot_CategoryAppBlock*)self, &a.category);
  1551.  
  1552.     len = pack_AppointmentAppInfo(&a, buffer, 0xffff);
  1553.     
  1554.     output = getByteArray(len);
  1555.     memcpy(unhand(output)->body, buffer, len);
  1556.     
  1557.     unhand(self)->raw = output;
  1558.     
  1559.     free(buffer);
  1560.     
  1561.     return output;
  1562. }
  1563.  
  1564. /* mail */
  1565. extern void Pdapilot_mail_Record_unpack(struct HPdapilot_mail_Record * self,  struct HArrayOfByte *b)
  1566. {
  1567.     struct Mail a;
  1568.     unpack_Mail(&a, unhand(b)->body, getArrayLength(b));
  1569.  
  1570.     if (a.dated)
  1571.       unhand(self)->date = makeJavaDateTm(&a.date);
  1572.     else
  1573.       unhand(self)->date = 0;
  1574.     
  1575.     unhand(self)->read = a.read;
  1576.     unhand(self)->signature = a.signature;
  1577.     unhand(self)->confirmRead = a.confirmRead;
  1578.     unhand(self)->confirmDelivery = a.confirmDelivery;
  1579.     unhand(self)->priority = a.priority;
  1580.     unhand(self)->addressing = a.addressing;
  1581.     
  1582.     unhand(self)->subject = a.subject ? makeJavaString(a.subject, strlen(a.subject)) : 0;
  1583.     unhand(self)->from = a.from ? makeJavaString(a.from, strlen(a.from)) : 0;
  1584.     unhand(self)->to = a.to ? makeJavaString(a.to, strlen(a.to)) : 0;
  1585.     unhand(self)->cc = a.cc ? makeJavaString(a.cc, strlen(a.cc)) : 0;
  1586.     unhand(self)->bcc = a.bcc ? makeJavaString(a.bcc, strlen(a.bcc)) : 0;
  1587.     unhand(self)->replyTo = a.replyTo ? makeJavaString(a.replyTo, strlen(a.replyTo)) : 0;
  1588.     unhand(self)->sentTo = a.sentTo ? makeJavaString(a.sentTo, strlen(a.sentTo)) : 0;
  1589.     unhand(self)->body = a.body ? makeJavaString(a.body, strlen(a.body)) : 0;
  1590.     
  1591.     free_Mail(&a);
  1592. }
  1593.  
  1594.  
  1595. extern HArrayOfByte* Pdapilot_mail_Record_pack(struct HPdapilot_mail_Record * self){
  1596.     char * buffer = malloc(0xffff);
  1597.     int len;
  1598.     HArrayOfByte * output;
  1599.     
  1600.     struct Mail a;
  1601.  
  1602.     a.dated = unhand(self)->date ? 1 : 0;
  1603.     if (a.dated)
  1604.       a.date = *readJavaDateTm(unhand(self)->date);
  1605.       
  1606.     a.read = unhand(self)->read;
  1607.     a.signature = unhand(self)->signature;
  1608.     a.confirmRead = unhand(self)->confirmRead;
  1609.     a.confirmDelivery = unhand(self)->confirmDelivery;
  1610.     a.priority = unhand(self)->priority;
  1611.     a.addressing = unhand(self)->addressing;
  1612.     
  1613.     a.subject = unhand(self)->subject ? makeCString(unhand(self)->subject) : 0;
  1614.     a.from = unhand(self)->from ? makeCString(unhand(self)->from) : 0;
  1615.     a.to = unhand(self)->to ? makeCString(unhand(self)->to) : 0;
  1616.     a.cc = unhand(self)->cc ? makeCString(unhand(self)->cc) : 0;
  1617.     a.bcc = unhand(self)->bcc ? makeCString(unhand(self)->bcc) : 0;
  1618.     a.replyTo = unhand(self)->replyTo ? makeCString(unhand(self)->replyTo) : 0;
  1619.     a.sentTo = unhand(self)->sentTo ? makeCString(unhand(self)->sentTo) : 0;
  1620.     a.body = unhand(self)->body ? makeCString(unhand(self)->body) : 0;
  1621.     
  1622.     len = pack_Mail(&a, buffer, 0xffff);
  1623.     
  1624.     output = getByteArray(len);
  1625.     memcpy(unhand(output)->body, buffer, len);
  1626.     
  1627.     unhand(self)->raw = output;
  1628.     
  1629.     free(buffer);
  1630.     
  1631.     return output;
  1632. }
  1633.  
  1634. extern void Pdapilot_mail_AppBlock_unpack(struct HPdapilot_mail_AppBlock * self,  struct HArrayOfByte *b)
  1635. {
  1636.     struct MailAppInfo a;
  1637.  
  1638.     unpack_MailAppInfo(&a, unhand(b)->body, getArrayLength(b));
  1639.     
  1640.     unhand(self)->raw = b;
  1641.  
  1642.     doUnpackCategories((HPdapilot_CategoryAppBlock*)self, &a.category);
  1643.     
  1644.     unhand(self)->dirty = a.dirty;
  1645.     unhand(self)->sortOrder = (HPdapilot_mail_sort*)
  1646.         execute_java_static_method(0, FindClass(0, "Pdapilot/mail/sort",1),
  1647.         "get", "(I)LPdapilot/mail/sort;", (long)a.sortOrder);
  1648.     unhand(self)->unsentMessage = a.unsentMessage ? makeJavaRecordID(a.unsentMessage) : 0;
  1649.  
  1650. }
  1651.  
  1652. extern HArrayOfByte* Pdapilot_mail_AppBlock_pack(struct HPdapilot_mail_AppBlock * self){
  1653.     char * buffer = malloc(0xffff);
  1654.     int len;
  1655.     HArrayOfByte * output;
  1656.     
  1657.     struct MailAppInfo a;
  1658.  
  1659.     doPackCategories((HPdapilot_CategoryAppBlock*)self, &a.category);
  1660.     
  1661.     a.sortOrder = (long)execute_java_dynamic_method(0, 
  1662.         (HObject*)unhand(self)->sortOrder, "getValue", "()I");
  1663.     a.dirty = unhand(self)->dirty;
  1664.     a.unsentMessage = unhand(self)->unsentMessage ? getJavaRecordID(unhand(self)->unsentMessage) : 0;
  1665.     
  1666.     len = pack_MailAppInfo(&a, buffer, 0xffff);
  1667.     
  1668.     output = getByteArray(len);
  1669.     memcpy(unhand(output)->body, buffer, len);
  1670.     
  1671.     unhand(self)->raw = output;
  1672.     
  1673.     free(buffer);
  1674.     
  1675.     return output;
  1676. }
  1677.  
  1678. extern void Pdapilot_mail_SyncPref_unpack(struct HPdapilot_mail_SyncPref * self,  struct HArrayOfByte *b)
  1679. {
  1680.     struct MailSyncPref a;
  1681.  
  1682.     unpack_MailSyncPref(&a, unhand(b)->body, getArrayLength(b));
  1683.     
  1684.     unhand(self)->raw = b;
  1685.     
  1686.     unhand(self)->syncType = (HPdapilot_mail_sync*)
  1687.         execute_java_static_method(0, FindClass(0, "Pdapilot/mail/sync",1),
  1688.         "get", "(I)LPdapilot/mail/sync;", (long)a.syncType);
  1689.     unhand(self)->getHigh = a.getHigh;
  1690.     unhand(self)->getContaining = a.getContaining;
  1691.     unhand(self)->truncate = a.truncate;
  1692.     unhand(self)->filterTo = a.filterTo ? makeJavaString(a.filterTo, strlen(a.filterTo)) : 0;
  1693.     unhand(self)->filterFrom = a.filterFrom ? makeJavaString(a.filterFrom, strlen(a.filterFrom)) : 0;
  1694.     unhand(self)->filterSubject = a.filterSubject ? makeJavaString(a.filterSubject, strlen(a.filterSubject)) : 0;
  1695.  
  1696. }
  1697.  
  1698. extern HArrayOfByte* Pdapilot_mail_SyncPref_pack(struct HPdapilot_mail_SyncPref * self){
  1699.     char * buffer = malloc(0xffff);
  1700.     int len;
  1701.     HArrayOfByte * output;
  1702.     
  1703.     struct MailSyncPref a;
  1704.     
  1705.     a.syncType = (long)execute_java_dynamic_method(0, 
  1706.         (HObject*)unhand(self)->syncType, "getValue", "()I");
  1707.     a.getHigh = unhand(self)->getHigh;
  1708.     a.getContaining = unhand(self)->getContaining;
  1709.     a.truncate = unhand(self)->truncate;
  1710.     a.filterTo = unhand(self)->filterTo ? makeCString(unhand(self)->filterTo) : 0;
  1711.     a.filterFrom = unhand(self)->filterFrom ? makeCString(unhand(self)->filterFrom) : 0;
  1712.     a.filterSubject = unhand(self)->filterSubject ? makeCString(unhand(self)->filterSubject) : 0;
  1713.     
  1714.     len = pack_MailSyncPref(&a, buffer, 0xffff);
  1715.     
  1716.     output = getByteArray(len);
  1717.     memcpy(unhand(output)->body, buffer, len);
  1718.     
  1719.     unhand(self)->raw = output;
  1720.     
  1721.     free(buffer);
  1722.     
  1723.     return output;
  1724. }
  1725.  
  1726. extern void Pdapilot_mail_SignaturePref_unpack(struct HPdapilot_mail_SignaturePref * self,  struct HArrayOfByte *b)
  1727. {
  1728.     struct MailSignaturePref a;
  1729.  
  1730.     unpack_MailSignaturePref(&a, unhand(b)->body, getArrayLength(b));
  1731.     
  1732.     unhand(self)->raw = b;
  1733.  
  1734.     unhand(self)->signature = a.signature ? makeJavaString(a.signature, strlen(a.signature)) : 0;
  1735.  
  1736. }
  1737.  
  1738. extern HArrayOfByte* Pdapilot_mail_SignaturePref_pack(struct HPdapilot_mail_SignaturePref * self){
  1739.     char * buffer = malloc(0xffff);
  1740.     int len;
  1741.     HArrayOfByte * output;
  1742.     
  1743.     struct MailSignaturePref a;
  1744.     
  1745.     a.signature = unhand(self)->signature ? makeCString(unhand(self)->signature) : 0;
  1746.  
  1747.     len = pack_MailSignaturePref(&a, buffer, 0xffff);
  1748.     
  1749.     output = getByteArray(len);
  1750.     memcpy(unhand(output)->body, buffer, len);
  1751.     
  1752.     unhand(self)->raw = output;
  1753.     
  1754.     free(buffer);
  1755.     
  1756.     return output;
  1757. }
  1758.  
  1759. /* expense */
  1760. extern void Pdapilot_expense_Record_unpack(struct HPdapilot_expense_Record * self,  struct HArrayOfByte *b)
  1761. {
  1762.     struct Expense a;
  1763.     unpack_Expense(&a, unhand(b)->body, getArrayLength(b));
  1764.  
  1765.     unhand(self)->date = makeJavaDateTm(&a.date);
  1766.  
  1767.     unhand(self)->type = (HPdapilot_expense_type*)
  1768.         execute_java_static_method(0, FindClass(0, "Pdapilot/expense/type",1),
  1769.         "get", "(I)LPdapilot/expense/type;", (long)a.type);
  1770.  
  1771.     unhand(self)->payment = (HPdapilot_expense_payment*)
  1772.         execute_java_static_method(0, FindClass(0, "Pdapilot/expense/payment",1),
  1773.         "get", "(I)LPdapilot/expense/payment;", (long)a.payment);
  1774.     
  1775.     unhand(self)->amount = a.amount ? makeJavaString(a.amount, strlen(a.amount)) : 0;
  1776.     unhand(self)->vendor = a.vendor ? makeJavaString(a.vendor, strlen(a.vendor)) : 0;
  1777.     unhand(self)->city = a.city ? makeJavaString(a.city, strlen(a.city)) : 0;
  1778.     unhand(self)->attendees = a.attendees ? makeJavaString(a.attendees, strlen(a.attendees)) : 0;
  1779.     unhand(self)->note = a.note ? makeJavaString(a.note, strlen(a.note)) : 0;
  1780.     
  1781.     free_Expense(&a);
  1782. }
  1783.  
  1784.  
  1785. extern HArrayOfByte* Pdapilot_expense_Record_pack(struct HPdapilot_expense_Record * self){
  1786.     char * buffer = malloc(0xffff);
  1787.     int len;
  1788.     HArrayOfByte * output;
  1789.     
  1790.     struct Expense a;
  1791.  
  1792.         a.date = *readJavaDateTm(unhand(self)->date);
  1793.       
  1794.     a.currency = unhand(self)->currency;
  1795.  
  1796.     a.type = (long)execute_java_dynamic_method(0, 
  1797.         (HObject*)unhand(self)->type, "getValue", "()I");
  1798.  
  1799.     a.payment = (long)execute_java_dynamic_method(0, 
  1800.         (HObject*)unhand(self)->payment, "getValue", "()I");
  1801.     
  1802.     a.amount = unhand(self)->amount ? makeCString(unhand(self)->amount) : 0;
  1803.     a.vendor = unhand(self)->vendor ? makeCString(unhand(self)->vendor) : 0;
  1804.     a.city = unhand(self)->city ? makeCString(unhand(self)->city) : 0;
  1805.     a.attendees = unhand(self)->attendees ? makeCString(unhand(self)->attendees) : 0;
  1806.     a.note = unhand(self)->note ? makeCString(unhand(self)->note) : 0;
  1807.     
  1808.     len = pack_Expense(&a, buffer, 0xffff);
  1809.     
  1810.     output = getByteArray(len);
  1811.     memcpy(unhand(output)->body, buffer, len);
  1812.     
  1813.     unhand(self)->raw = output;
  1814.     
  1815.     free(buffer);
  1816.     
  1817.     return output;
  1818. }
  1819.  
  1820. extern void Pdapilot_expense_AppBlock_unpack(struct HPdapilot_expense_AppBlock * self,  struct HArrayOfByte *b)
  1821. {
  1822.     int i;
  1823.     struct ExpenseAppInfo a;
  1824.     stack_item l;
  1825.  
  1826.     unpack_ExpenseAppInfo(&a, unhand(b)->body, getArrayLength(b));
  1827.     
  1828.     unhand(self)->raw = b;
  1829.     
  1830.     l.i = 4;
  1831.     
  1832.     unhand(self)->currencies = (HArrayOfObject*)MultiArrayAlloc(1,
  1833.         FindClass(0, "Pdapilot/expense/CustomCurrency",1),
  1834.         &l);
  1835.  
  1836.     if (!unhand(self)->currencies)
  1837.         return;
  1838.     
  1839.     for(i=0;i<4;i++) {
  1840.         struct ExpenseCustomCurrency * ecc;
  1841.         HPdapilot_expense_CustomCurrency * c = 
  1842.             (HPdapilot_expense_CustomCurrency*)execute_java_constructor(0, 
  1843.                 "Pdapilot/expense/CustomCurrency", 0, "()");
  1844.         unhand(unhand(self)->currencies)->body[i] = (HObject*)c;
  1845.         ecc = &a.currencies[i];
  1846.         unhand(c)->symbol = ecc->symbol ? makeJavaString(ecc->symbol, strlen(ecc->symbol)) : 0;
  1847.         unhand(c)->name = ecc->name ? makeJavaString(ecc->name, strlen(ecc->name)) : 0;
  1848.         unhand(c)->rate = ecc->rate ? makeJavaString(ecc->rate, strlen(ecc->rate)) : 0;
  1849.     }    
  1850.  
  1851.     doUnpackCategories((HPdapilot_CategoryAppBlock*)self, &a.category);
  1852.     
  1853.     unhand(self)->sortOrder = (HPdapilot_expense_sort*)
  1854.         execute_java_static_method(0, FindClass(0, "Pdapilot/expense/sort",1),
  1855.         "get", "(I)LPdapilot/expense/sort;", (long)a.sortOrder);;
  1856.     
  1857. }
  1858.  
  1859. extern HArrayOfByte* Pdapilot_expense_AppBlock_pack(struct HPdapilot_expense_AppBlock * self){
  1860.     char * buffer = malloc(0xffff);
  1861.     int len;
  1862.     int i;
  1863.     HArrayOfByte * output;
  1864.     
  1865.     struct ExpenseAppInfo a;
  1866.     
  1867.     a.sortOrder = (long)execute_java_dynamic_method(0, 
  1868.         (HObject*)unhand(self)->sortOrder, "getValue", "()I");
  1869.  
  1870.     if (unhand(self)->currencies)
  1871.         for(i=0;i<4;i++) {
  1872.             HPdapilot_expense_CustomCurrency * c = 
  1873.                 (HPdapilot_expense_CustomCurrency*)
  1874.                 unhand(unhand(self)->currencies)->body[i];
  1875.             if (unhand(c)->name)
  1876.                 javaString2CString(unhand(c)->name, a.currencies[i].name, 16);
  1877.             else
  1878.                 a.currencies[i].name[0] = 0;
  1879.             if (unhand(c)->symbol)
  1880.                 javaString2CString(unhand(c)->symbol, a.currencies[i].symbol, 4);
  1881.             else
  1882.                 a.currencies[i].symbol[0] = 0;
  1883.             if (unhand(c)->rate)
  1884.                 javaString2CString(unhand(c)->rate, a.currencies[i].rate, 8);
  1885.             else
  1886.                 a.currencies[i].rate[0] = 0;
  1887.         }    
  1888.  
  1889.     doPackCategories((HPdapilot_CategoryAppBlock*)self, &a.category);
  1890.     
  1891.     len = pack_ExpenseAppInfo(&a, buffer, 0xffff);
  1892.     
  1893.     output = getByteArray(len);
  1894.     memcpy(unhand(output)->body, buffer, len);
  1895.     
  1896.     unhand(self)->raw = output;
  1897.     
  1898.     free(buffer);
  1899.     
  1900.     return output;
  1901. }
  1902.  
  1903. extern void Pdapilot_expense_Pref_unpack(struct HPdapilot_expense_Pref * self,  struct HArrayOfByte *b)
  1904. {
  1905.     struct ExpensePref a;
  1906.     int i;
  1907.  
  1908.     unpack_ExpensePref(&a, unhand(b)->body, getArrayLength(b));
  1909.     
  1910.     unhand(self)->raw = b;
  1911.     
  1912.     unhand(self)->currentCategory = a.currentCategory;
  1913.     unhand(self)->defaultCategory = a.defaultCategory;
  1914.     unhand(self)->currentCategory = a.noteFont;
  1915.     unhand(self)->showAllCategories = a.showAllCategories;
  1916.     unhand(self)->showCurrency = a.showCurrency;
  1917.     unhand(self)->saveBackup = a.saveBackup;
  1918.     unhand(self)->allowQuickFill = a.allowQuickFill;
  1919.     unhand(self)->unitOfDistance = (HPdapilot_expense_distance*)
  1920.         execute_java_static_method(0, FindClass(0, "Pdapilot/expense/distance",1),
  1921.         "get", "(I)LPdapilot/expense/distance;", (long)a.unitOfDistance);
  1922.  
  1923.     unhand(self)->currencies = makeIntArray(7);
  1924.     for (i=0;i<7;i++)
  1925.         unhand(unhand(self)->currencies)->body[i] = a.currencies[i];
  1926.  
  1927. }
  1928.  
  1929. extern HArrayOfByte* Pdapilot_expense_Pref_pack(struct HPdapilot_expense_Pref * self){
  1930.     char * buffer = malloc(0xffff);
  1931.     int len;
  1932.     int i;
  1933.     HArrayOfByte * output;
  1934.     
  1935.     struct ExpensePref a;
  1936.     
  1937.     a.currentCategory = unhand(self)->currentCategory;
  1938.     a.defaultCategory = unhand(self)->defaultCategory;
  1939.     a.noteFont = unhand(self)->currentCategory;
  1940.     a.showAllCategories = unhand(self)->showAllCategories;
  1941.     a.showCurrency = unhand(self)->showCurrency;
  1942.     a.saveBackup = unhand(self)->saveBackup;
  1943.     a.allowQuickFill = unhand(self)->allowQuickFill;
  1944.     a.unitOfDistance = (long)execute_java_dynamic_method(0, 
  1945.         (HObject*)unhand(self)->unitOfDistance, "getValue", "()I");
  1946.  
  1947.     for (i=0;i<7;i++)
  1948.         a.currencies[i] = unhand(unhand(self)->currencies)->body[i];
  1949.     
  1950.     len = pack_ExpensePref(&a, buffer, 0xffff);
  1951.     
  1952.     output = getByteArray(len);
  1953.     memcpy(unhand(output)->body, buffer, len);
  1954.     
  1955.     unhand(self)->raw = output;
  1956.     
  1957.     free(buffer);
  1958.     
  1959.     return output;
  1960. }
  1961.  
  1962. extern void Pdapilot_File_pi_file_create(struct HPdapilot_File * self,struct Hjava_lang_String * name,struct HPdapilot_DBInfo * info)
  1963. {
  1964.     struct pi_file * pf;
  1965.     struct DBInfo dbInfo;
  1966.     dbInfo.flags = 
  1967.         (unhand(info)->flagReadOnly ? dlpDBFlagReadOnly : 0) |
  1968.         (unhand(info)->flagResource ? dlpDBFlagResource : 0) |
  1969.         (unhand(info)->flagBackup ? dlpDBFlagBackup : 0) |
  1970.         (unhand(info)->flagOpen ? dlpDBFlagOpen : 0) |
  1971.         (unhand(info)->flagAppInfoDirty ? dlpDBFlagAppInfoDirty : 0) |
  1972.         (unhand(info)->flagNewer ? dlpDBFlagNewer : 0) |
  1973.         (unhand(info)->flagReset ? dlpDBFlagReset : 0);
  1974.     dbInfo.miscFlags = (unhand(info)->flagExcludeFromSync ? dlpDBMiscFlagExcludeFromSync : 0);
  1975.     dbInfo.version = unhand(info)->version;
  1976.     dbInfo.modnum = unhand(info)->modnum;
  1977.     dbInfo.type = getJavaChar4(unhand(info)->type);
  1978.     dbInfo.creator = getJavaChar4(unhand(info)->creator);
  1979.     dbInfo.createDate = readJavaDate(unhand(info)->createDate);
  1980.     dbInfo.modifyDate = readJavaDate(unhand(info)->modifyDate);
  1981.     dbInfo.backupDate = readJavaDate(unhand(info)->backupDate);
  1982.     javaString2CString(unhand(info)->name, dbInfo.name, 34);
  1983.     
  1984.     unhand(self)->_pf = 0;
  1985.     pf = pi_file_create(makeCString(name), &dbInfo);
  1986.     if (!pf) {
  1987.         throwIOException(errno);
  1988.         return;
  1989.     }
  1990.     unhand(self)->_pf = (javaint_t)pf;
  1991. }
  1992.  
  1993. extern void Pdapilot_File_pi_file_open(struct HPdapilot_File * self,struct Hjava_lang_String * name)
  1994. {
  1995.     struct pi_file * pf = pi_file_open(makeCString(name));
  1996.     unhand(self)->_pf = 0;
  1997.     if (!pf) {
  1998.         throwIOException(errno);
  1999.         return;
  2000.     }
  2001.     unhand(self)->_pf = (javaint_t)pf;
  2002. }
  2003.  
  2004. extern void Pdapilot_File_pi_file_close(struct HPdapilot_File * self)
  2005. {
  2006.     if (unhand(self)->_pf) {
  2007.         pi_file_close((struct pi_file*)(unhand(self)->_pf));
  2008.         unhand(self)->_pf = 0;
  2009.     }
  2010. }
  2011.  
  2012. extern void Pdapilot_File_pi_file_install(struct HPdapilot_File * self, javaint_t socket, javaint_t cardno)
  2013. {
  2014.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2015.     int result = pi_file_install(pf, socket, cardno);
  2016.     
  2017.     if (result<0) {
  2018.         throwIOException(errno);
  2019.     }
  2020. }
  2021.  
  2022. extern void Pdapilot_File_pi_file_retrieve(struct HPdapilot_File * self, javaint_t socket, javaint_t cardno)
  2023. {
  2024.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2025.     int result = pi_file_retrieve(pf, socket, cardno);
  2026.     
  2027.     if (result<0) {
  2028.         throwIOException(errno);
  2029.     }
  2030. }
  2031.  
  2032. extern void Pdapilot_File_pi_file_merge(struct HPdapilot_File * self, javaint_t socket, javaint_t cardno)
  2033. {
  2034.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2035.     int result = pi_file_merge(pf, socket, cardno);
  2036.     
  2037.     if (result<0) {
  2038.         throwIOException(errno);
  2039.     }
  2040. }
  2041.  
  2042. extern javaint_t Pdapilot_File_pi_file_get_entries(struct HPdapilot_File * self)
  2043. {
  2044.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2045.     int entries;
  2046.     int result = pi_file_get_entries(pf, &entries);
  2047.     
  2048.     if (result < 0) {
  2049.         throwIOException(errno);
  2050.         return 0;
  2051.     }
  2052.     
  2053.     return entries;
  2054. }
  2055.  
  2056. extern struct HPdapilot_Record *Pdapilot_File_pi_file_read_record(struct HPdapilot_File * self, javaint_t index ,struct HPdapilot_Database * dbClass)
  2057. {
  2058.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2059.     int attr, cat;
  2060.     recordid_t id;
  2061.     int len;
  2062.     void * buffer;
  2063.     HPdapilot_Record * output = NULL;
  2064.     
  2065.     int result = pi_file_read_record(pf, index, &buffer, &len, &attr, &cat, &id);
  2066.     
  2067.     if (result >= 0) {
  2068.         HArrayOfByte * a = getByteArray(len);
  2069.         memcpy(unhand(a)->body, buffer, len);
  2070.         output = (HPdapilot_Record*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  2071.             "newRecord", "([BLPdapilot/RecordID;III)LPdapilot/Record;",
  2072.             a, makeJavaRecordID(id), (javaint_t)index, (javaint_t)attr, (javaint_t)cat);
  2073.     } else {
  2074.         throwIOException(errno);
  2075.         return 0;
  2076.     }
  2077.     
  2078.     return output;
  2079. }
  2080.  
  2081. extern struct HPdapilot_Resource *Pdapilot_File_pi_file_read_resource(struct HPdapilot_File * self, javaint_t index ,struct HPdapilot_Database * dbClass)
  2082. {
  2083.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2084.     int id;
  2085.     unsigned long type;
  2086.     int len;
  2087.     void * buffer;
  2088.     HPdapilot_Resource * output = NULL;
  2089.     
  2090.     int result = pi_file_read_resource(pf, index, &buffer, &len, &type, &id);
  2091.     
  2092.     if (result >= 0) {
  2093.         HArrayOfByte * a = getByteArray(len);
  2094.         memcpy(unhand(a)->body, buffer, len);
  2095.         output = (HPdapilot_Resource*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  2096.             "newResource", "([BLPdapilot/Char4;II)LPdapilot/Resource;",
  2097.             a, type, (javaint_t)id, (javaint_t)index);
  2098.     } else {
  2099.         throwIOException(errno);
  2100.         return 0;
  2101.     }
  2102.     
  2103.     return output;
  2104. }
  2105.  
  2106. extern struct HPdapilot_Record *Pdapilot_File_pi_file_read_record_by_id(struct HPdapilot_File * self, struct HPdapilot_RecordID * jid ,struct HPdapilot_Database * dbClass)
  2107. {
  2108.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2109.     int attr, cat, index;
  2110.     recordid_t id = getJavaRecordID(jid);
  2111.     int len;
  2112.     void * buffer;
  2113.     HPdapilot_Record * output = NULL;
  2114.     
  2115.     int result = pi_file_read_record_by_id(pf, id, &buffer, &len, &index, &attr, &cat);
  2116.     
  2117.     if (result >= 0) {
  2118.         HArrayOfByte * a = getByteArray(len);
  2119.         memcpy(unhand(a)->body, buffer, len);
  2120.         output = (HPdapilot_Record*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  2121.             "newRecord", "([BLPdapilot/RecordID;III)LPdapilot/Record;",
  2122.             a, makeJavaRecordID(id), (javaint_t)index, (javaint_t)attr, (javaint_t)cat);
  2123.     } else  {
  2124.         throwIOException(errno);
  2125.         return 0;
  2126.     }
  2127.     
  2128.     return output;
  2129. }
  2130.  
  2131. extern struct HPdapilot_DBInfo * Pdapilot_File_pi_file_get_info(struct HPdapilot_File * self)
  2132. {
  2133.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2134.     struct HPdapilot_DBInfo * output;
  2135.     struct DBInfo i;
  2136.     
  2137.     if (pi_file_get_info(pf, &i)<0) {
  2138.         throwIOException(errno);
  2139.         return 0;
  2140.     }
  2141.     
  2142.     output = (HPdapilot_DBInfo*)execute_java_constructor(0,
  2143.          "Pdapilot/DBInfo", 0, "()");
  2144.          
  2145.     unhand(output)->flagReadOnly = !!(i.flags & dlpDBFlagReadOnly);
  2146.     unhand(output)->flagResource = !!(i.flags & dlpDBFlagResource);
  2147.     unhand(output)->flagBackup = !!(i.flags & dlpDBFlagBackup);
  2148.     unhand(output)->flagOpen = !!(i.flags & dlpDBFlagOpen);
  2149.     unhand(output)->flagAppInfoDirty = !!(i.flags & dlpDBFlagAppInfoDirty);
  2150.     unhand(output)->flagNewer = !!(i.flags & dlpDBFlagNewer);
  2151.     unhand(output)->flagReset = !!(i.flags & dlpDBFlagReset);
  2152.     unhand(output)->flagExcludeFromSync = !!(i.miscFlags & dlpDBMiscFlagExcludeFromSync);
  2153.     unhand(output)->index = i.index;
  2154.     unhand(output)->version = i.version;
  2155.     unhand(output)->modnum = i.modnum;
  2156.     unhand(output)->type = makeJavaChar4(i.type);
  2157.     unhand(output)->creator = makeJavaChar4(i.creator);
  2158.     unhand(output)->createDate = makeJavaDate(i.createDate);
  2159.     unhand(output)->modifyDate = makeJavaDate(i.modifyDate);
  2160.     unhand(output)->backupDate = makeJavaDate(i.backupDate);
  2161.     unhand(output)->name = makeJavaString(i.name, strlen(i.name));
  2162.     unhand(output)->card = 0;
  2163.  
  2164.     unhand(output)->more = i.more;
  2165.  
  2166.     return output;
  2167. }
  2168.  
  2169. extern void Pdapilot_File_pi_file_set_info(struct HPdapilot_File * self, struct HPdapilot_DBInfo * info)
  2170. {
  2171.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2172.     struct DBInfo dbInfo;
  2173.     dbInfo.flags = 
  2174.         (unhand(info)->flagReadOnly ? dlpDBFlagReadOnly : 0) |
  2175.         (unhand(info)->flagResource ? dlpDBFlagResource : 0) |
  2176.         (unhand(info)->flagBackup ? dlpDBFlagBackup : 0) |
  2177.         (unhand(info)->flagOpen ? dlpDBFlagOpen : 0) |
  2178.         (unhand(info)->flagAppInfoDirty ? dlpDBFlagAppInfoDirty : 0) |
  2179.         (unhand(info)->flagNewer ? dlpDBFlagNewer : 0) |
  2180.         (unhand(info)->flagReset ? dlpDBFlagReset : 0);
  2181.     dbInfo.miscFlags = (unhand(info)->flagExcludeFromSync ? dlpDBMiscFlagExcludeFromSync : 0);
  2182.     dbInfo.version = unhand(info)->version;
  2183.     dbInfo.modnum = unhand(info)->modnum;
  2184.     dbInfo.type = getJavaChar4(unhand(info)->type);
  2185.     dbInfo.creator = getJavaChar4(unhand(info)->creator);
  2186.     dbInfo.createDate = readJavaDate(unhand(info)->createDate);
  2187.     dbInfo.modifyDate = readJavaDate(unhand(info)->modifyDate);
  2188.     dbInfo.backupDate = readJavaDate(unhand(info)->backupDate);
  2189.     javaString2CString(unhand(info)->name, dbInfo.name, 34);
  2190.     
  2191.     if (pi_file_set_info(pf, &dbInfo)<0)
  2192.         throwIOException(errno);
  2193. }
  2194.  
  2195. extern void Pdapilot_File_pi_file_set_app_info(struct HPdapilot_File * self, struct HPdapilot_AppBlock * appblock)
  2196. {
  2197.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2198.     HArrayOfByte * b;
  2199.     char * buffer;
  2200.     int len;
  2201.     int result;
  2202.     
  2203.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)appblock, "pack", "()[B");
  2204.     if (!b)
  2205.         return;
  2206.     
  2207.     buffer = unhand(b)->body;
  2208.     len = getArrayLength(b);
  2209.     
  2210.     result = pi_file_set_app_info(pf, buffer, len);
  2211.     
  2212.     if (result < 0)
  2213.         throwIOException(errno);
  2214. }
  2215.  
  2216. extern struct HPdapilot_AppBlock *Pdapilot_File_pi_file_get_app_info(struct HPdapilot_File * self, HPdapilot_Database * dbClass)
  2217. {
  2218.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2219.     void * buffer;
  2220.     int len;
  2221.     HPdapilot_AppBlock * output;
  2222.     
  2223.     int result = pi_file_get_app_info(pf, &buffer, &len);
  2224.     
  2225.     if (result >= 0) {
  2226.         HArrayOfByte * a;
  2227.         len = result;
  2228.         a = getByteArray(len);
  2229.         memcpy(unhand(a)->body, buffer, len);
  2230.         output = (HPdapilot_AppBlock*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  2231.             "newAppBlock", "([B)LPdapilot/AppBlock;",
  2232.             a);
  2233.     } else {
  2234.         throwIOException(errno);
  2235.         return 0;
  2236.     }
  2237.     
  2238.     return output;
  2239. }
  2240.  
  2241.  
  2242. extern struct HPdapilot_SortBlock *Pdapilot_File_pi_file_get_sort_info(struct HPdapilot_File * self, HPdapilot_Database * dbClass)
  2243. {
  2244.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2245.     void * buffer;
  2246.     int len;
  2247.     HPdapilot_SortBlock * output;
  2248.     
  2249.     int result = pi_file_get_app_info(pf, &buffer, &len);
  2250.     
  2251.     if (result >= 0) {
  2252.         HArrayOfByte * a;
  2253.         len = result;
  2254.         a = getByteArray(len);
  2255.         memcpy(unhand(a)->body, buffer, len);
  2256.         output = (HPdapilot_SortBlock*)execute_java_dynamic_method(0, (HObject*)dbClass, 
  2257.             "newSortBlock", "([B)LPdapilot/SortBlock;",
  2258.             a);
  2259.     } else {
  2260.         throwIOException(errno);
  2261.         return 0;
  2262.     }
  2263.     
  2264.     return output;
  2265. }
  2266.  
  2267. extern void Pdapilot_File_pi_file_set_sort_info(struct HPdapilot_File * self, struct HPdapilot_SortBlock * sortblock)
  2268. {
  2269.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2270.     HArrayOfByte * b;
  2271.     char * buffer;
  2272.     int len;
  2273.     int result;
  2274.     
  2275.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)sortblock, "pack", "()[B");
  2276.     if (!b)
  2277.         return;
  2278.     
  2279.     buffer = unhand(b)->body;
  2280.     len = getArrayLength(b);
  2281.     
  2282.     result = pi_file_set_sort_info(pf, buffer, len);
  2283.     
  2284.     if (result < 0)
  2285.         throwIOException(errno);
  2286. }
  2287.  
  2288. extern void Pdapilot_File_pi_file_append_record(struct HPdapilot_File * self, HPdapilot_Record * record)
  2289. {
  2290.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2291.     int attr, cat;
  2292.     HArrayOfByte * b;
  2293.     char * buffer;
  2294.     int len;
  2295.     recordid_t id;
  2296.     int result;
  2297.     
  2298.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)record, "pack", "()[B");
  2299.     if (!b)
  2300.         return;
  2301.     
  2302.     id = getJavaRecordID(unhand(record)->id);
  2303.     attr = 0;
  2304.     attr |= unhand(record)->deleted ? 0x80 : 0;
  2305.     attr |= unhand(record)->modified ? 0x40 : 0;
  2306.     attr |= unhand(record)->busy ? 0x20 : 0;
  2307.     attr |= unhand(record)->secret ? 0x10 : 0;
  2308.     attr |= unhand(record)->archived ? 0x08 : 0;
  2309.     cat = unhand(record)->category;
  2310.     buffer = unhand(b)->body;
  2311.     len = getArrayLength(b);
  2312.     
  2313.     result = pi_file_append_record(pf, buffer, len, attr, cat, id);
  2314.     
  2315.     if (result < 0)
  2316.         throwIOException(errno);
  2317. }
  2318.  
  2319. extern void Pdapilot_File_pi_file_append_resource(struct HPdapilot_File * self, HPdapilot_Resource * resource)
  2320. {
  2321.     struct pi_file * pf = (struct pi_file*)unhand(self)->_pf;
  2322.     char * buffer;
  2323.     HArrayOfByte * b;
  2324.     int len;
  2325.     javaint_t type;
  2326.     javaint_t id;
  2327.     int result;
  2328.  
  2329.     b = (HArrayOfByte*)execute_java_dynamic_method(0, (HObject*)resource, "pack", "()[B");
  2330.     if (!b)
  2331.         return;
  2332.     
  2333.     type = unhand(unhand(resource)->type)->value;
  2334.     id = unhand(resource)->id;
  2335.     buffer = unhand(b)->body;
  2336.     len = getArrayLength(b);
  2337.     
  2338.     result = pi_file_append_resource(pf, buffer, len, type, id);
  2339.     
  2340.     if (result < 0)
  2341.         throwIOException(errno);
  2342. }
  2343.